@@ -223,13 +223,17 @@ def _ensure_arraylike(values, func_name: str) -> ArrayLike:
223
223
"""
224
224
ensure that we are arraylike if not already
225
225
"""
226
- if not isinstance (values , (ABCIndex , ABCSeries , ABCExtensionArray , np .ndarray )):
226
+ if not isinstance (
227
+ values ,
228
+ (ABCIndex , ABCSeries , ABCExtensionArray , np .ndarray , ABCNumpyExtensionArray ),
229
+ ):
227
230
# GH#52986
228
231
if func_name != "isin-targets" :
229
232
# Make an exception for the comps argument in isin.
230
233
raise TypeError (
231
234
f"{ func_name } requires a Series, Index, "
232
- f"ExtensionArray, or np.ndarray, got { type (values ).__name__ } ."
235
+ f"ExtensionArray, np.ndarray or NumpyExtensionArray "
236
+ f"got { type (values ).__name__ } ."
233
237
)
234
238
235
239
inferred = lib .infer_dtype (values , skipna = False )
@@ -325,15 +329,15 @@ def unique(values):
325
329
326
330
Returns
327
331
-------
328
- numpy.ndarray or ExtensionArray
332
+ numpy.ndarray, ExtensionArray or NumpyExtensionArray
329
333
330
334
The return can be:
331
335
332
336
* Index : when the input is an Index
333
337
* Categorical : when the input is a Categorical dtype
334
338
* ndarray : when the input is a Series/ndarray
335
339
336
- Return numpy.ndarray or ExtensionArray .
340
+ Return numpy.ndarray, ExtensionArray or NumpyExtensionArray .
337
341
338
342
See Also
339
343
--------
@@ -405,6 +409,13 @@ def unique(values):
405
409
406
410
>>> pd.unique(pd.Series([("a", "b"), ("b", "a"), ("a", "c"), ("b", "a")]).values)
407
411
array([('a', 'b'), ('b', 'a'), ('a', 'c')], dtype=object)
412
+
413
+ An NumpyExtensionArray of complex
414
+
415
+ >>> pd.unique(pd.array([1 + 1j, 2, 3]))
416
+ <NumpyExtensionArray>
417
+ [(1+1j), (2+0j), (3+0j)]
418
+ Length: 3, dtype: complex128
408
419
"""
409
420
return unique_with_mask (values )
410
421
0 commit comments