Skip to content

BUG: pd.unique() does not accept NumpyExtensionArray #59213

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

Closed
2 of 3 tasks
mutricyl opened this issue Jul 8, 2024 · 2 comments · Fixed by #59214
Closed
2 of 3 tasks

BUG: pd.unique() does not accept NumpyExtensionArray #59213

mutricyl opened this issue Jul 8, 2024 · 2 comments · Fixed by #59214
Assignees
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@mutricyl
Copy link
Contributor

mutricyl commented Jul 8, 2024

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.

Reproducible Example

import pandas as pd
arr_int = pd.array([1, 2, 3]) # Int64Dtype() => ExtensionArray
arr_complex = pd.array([1+1j, 2, 3]) # NumpyEADtype('complex128') => NumpyExtensionArray

pd.unique(arr_int)  # OK
pd.unique(arr_complex)  # NOK: TypeError: unique requires a Series, Index, ExtensionArray, or np.ndarray, got NumpyExtensionArray.

Issue Description

This issue is similar to #59177 and is coming from pint-pandas where test CI job with nightly builds from pandas was recently introduced (pint-pandas issue related to skipped tests to pass tests with pandas 3).

The above example is fine with pandas 2.2.2 but fails with pandas nightlies

The above mentionned TypeError is coming from

def _ensure_arraylike(values, func_name: str) -> ArrayLike:

As explained in #59177 NumpyExtensionArray may be used internally when other type of ExtensionArray are not available.

Expected Behavior

for pandas 2.2.2 pd.unique returns:

>>> pd.unique(arr_complex)
array([1.+1.j, 2.+0.j, 3.+0.j])

While we expect

>>> pd.unique(arr_complex)
<NumpyExtensionArray>
[(1+1j), (2+0j), (3+0j)]
Length: 3, dtype: complex128

Installed Versions

Replace this line with the output of pd.show_versions()

@mutricyl mutricyl added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 8, 2024
@ritwizsinha
Copy link
Contributor

take

@ritwizsinha
Copy link
Contributor

Added a similar PR like #59181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants