-
-
Notifications
You must be signed in to change notification settings - Fork 19k
Closed
Labels
AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBug
Description
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Reproducible Example
import pandas as pd
import numpy as np
arr = pd.arrays.NumpyExtensionArray(np.array([1,2,3]))
pd.api.extensions.take(arr,[2])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\mambaforge\envs\test_py300\Lib\site-packages\pandas\core\algorithms.py", line 1166, in take
raise TypeError(
TypeError: pd.api.extensions.take requires a numpy.ndarray, ExtensionArray, Index, or Series, got NumpyExtensionArray.
Issue Description
I'd expect NumpyExtensionArray to be considered an ExtensionArray, so compatable with pd.api.extensions.take.
Expected Behavior
return
<NumpyExtensionArray>
[2]
Length: 1, dtype: int32
Installed Versions
Replace this line with the output of pd.show_versions()
Metadata
Metadata
Assignees
Labels
AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBug
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Aloqeely commentedon Jul 4, 2024
Thanks for the report! I'm surprised that
NumpyExtensionArray
fails theisinstance
check. cc @jbrockmendelOn a separate matter, is there a specific reason you're using
NumpyExtensionArray
? I don't think there are many benefits to using it.mutricyl commentedon Jul 4, 2024
For the record this issue is linked to pint-pandas development and particularly hgrecco/pint-pandas#239.
New version of
pandas.core.algorithms.take
function introduced in #52981 is very restrictive and I wonder whyNumpyExtensionArray
is not in the list.NumpyExtensionArray
is used aspd.array
is used inPintArray
constructor. Depending on provided dtypepd.array
will result on aExtensionArray
subclass or will fall back onNumpyExtensionArray
.For example:
There is no build in pandas
ExtensionArray
for complex so pd.array falls back toNumpyExtensionArray
rhshadrach commentedon Jul 4, 2024
If the check is disabled, the take operation appears to work without issue. Agreed this should work - PRs to fix are welcome.
mutricyl commentedon Jul 4, 2024
take
update algo.take to solve pandas-dev#59177
update algo.take to solve #59177 (#59181)