-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: assigning Series.array / PandasArray to column fails #26390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This seems to work for me In [1]: import pandas as pd
In [2]: pd.__version__
Out[2]: '0.24.2'
In [3]: df = pd.DataFrame({'a': [1, 2, 3, 4], 'b': ['a', 'b', 'c', 'd']})
In [4]: df['c'] = pd.array([1, 2, None, 3])
In [5]: df
Out[5]:
a b c
0 1 a 1
1 2 b 2
2 3 c None
3 4 d 3 |
Indeed, on 0.24.2 it 'seems' to work, but we incorrectly store the PandasArray (which I think we fixed). It is however on master that this is failing. |
The current master implementation does seem to convert any if isinstance(values, ABCPandasArray):
values = values.to_numpy()
if isinstance(dtype, PandasDtype):
dtype = dtype.numpy_dtype |
Thanks for looking into it! |
Without converting the PandasArray to a Numpy Array the block type assigned is
pandas/pandas/core/internals/blocks.py Lines 1511 to 1515 in e5d15b2
This is not true for If we pass a NumpyArray instead of a PandasArray, then the during the call to the Lines 3400 to 3413 in e5d15b2
the Line 3635 in e5d15b2
This step is left out when we convert the PandasArray to a numpy array. Perhaps we can add this after the pandas/pandas/core/internals/blocks.py Lines 3032 to 3039 in e5d15b2
|
If we simply add a line pandas/pandas/core/internals/blocks.py Line 3036 in e5d15b2
then the following test will fail pandas/pandas/tests/internals/test_internals.py Lines 1295 to 1312 in ff4437e
However, with the bug in hand, and the new implementation of passing Another solution can be to convert the Lines 3623 to 3625 in e5d15b2
or add a special case of |
Assigning a PandasArray (so also the result of
df['a'].array
) of the correct length to add a column fails:Note this only fails for the PandasArray types (so when creating a FloatBlock or IntBlock, .. which expect 2D data, so when not creating an ExtensionBlock as is done for an "actual" ExtensionArray).
The text was updated successfully, but these errors were encountered: