diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index a67d31344ff55..8e33596bd86c1 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1264,7 +1264,7 @@ def shift(self, periods, fill_value=None): return self.from_codes(codes, dtype=self.dtype) - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: """ The numpy array interface. diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 06c1338dbf5ab..6b11f156dafa0 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -481,7 +481,7 @@ def _formatter(self, boxed=False): def nbytes(self): return self._data.nbytes - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: # used for Timedelta/DatetimeArray, overwritten by PeriodArray if is_object_dtype(dtype): return np.array(list(self), dtype=object) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index d9c4b27da8698..ba89c55a8a86e 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -562,7 +562,7 @@ def _resolution(self): # ---------------------------------------------------------------- # Array-Like / EA-Interface Methods - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: if dtype is None and self.tz: # The default for tz-aware is object, to preserve tz info dtype = object diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 75dd00104db1b..2a09cbfdb2386 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -1063,7 +1063,7 @@ def is_non_overlapping_monotonic(self): ) # Conversion - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: """ Return the IntervalArray's data as a numpy array of Interval objects (with dtype='object') diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 6fd9f1efbb408..0253cab39fb45 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -136,7 +136,7 @@ def to_numpy( __array_priority__ = 1000 # higher than ndarray so ops dispatch to us - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: """ the array interface, return my values We return an object array here to preserve our scalar values diff --git a/pandas/core/arrays/numpy_.py b/pandas/core/arrays/numpy_.py index 3ad6e7cb3c176..4db3d3010adaf 100644 --- a/pandas/core/arrays/numpy_.py +++ b/pandas/core/arrays/numpy_.py @@ -182,7 +182,7 @@ def dtype(self): # ------------------------------------------------------------------------ # NumPy Array Interface - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: return np.asarray(self._ndarray, dtype=dtype) _HANDLED_TYPES = (np.ndarray, numbers.Number) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index db84a522f55b1..2bca4e642841f 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -279,7 +279,7 @@ def freq(self): """ return self.dtype.freq - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: # overriding DatetimelikeArray return np.array(list(self), dtype=object) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 95d6136a2dad6..e2562a375515d 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -427,7 +427,7 @@ def from_spmatrix(cls, data): return cls._simple_new(arr, index, dtype) - def __array__(self, dtype=None, copy=True): + def __array__(self, dtype=None, copy=True) -> np.ndarray: fill_value = self.fill_value if self.sp_index.ngaps == 0: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 22655bf9889c7..be1c0a9c785a0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1882,7 +1882,7 @@ def empty(self) -> bool_t: # GH#23114 Ensure ndarray.__op__(DataFrame) returns NotImplemented __array_priority__ = 1000 - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: return com.values_from_object(self) def __array_wrap__(self, result, context=None): diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b02c0a08c93fa..1489e100b5682 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -597,7 +597,7 @@ def __len__(self) -> int: """ return len(self._data) - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: """ The array interface, return my values. """ diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index 7c1e95e12d339..41072d4ce6a93 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -392,7 +392,7 @@ def __contains__(self, key) -> bool: return contains(self, key, container=self._engine) - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: """ the array interface, return my values """ return np.array(self._data, dtype=dtype) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 0c40900d54b53..952a788f77347 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -294,7 +294,7 @@ def _simple_new(cls, values, name=None, freq=None, tz=None, dtype=None): # -------------------------------------------------------------------- - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: return np.asarray(self._data, dtype=dtype) @cache_readonly diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 1144e6d597fba..84d7399cc4f2d 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -951,7 +951,7 @@ def copy( _set_identity=_set_identity, ) - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: """ the array interface, return my values """ return self.values diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index cc10197f80c6f..6ab2e66e05d6e 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -391,7 +391,7 @@ def _int64index(self): # ------------------------------------------------------------------------ # Index Methods - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: if is_integer_dtype(dtype): return self.asi8 else: diff --git a/pandas/core/series.py b/pandas/core/series.py index 446654374f37c..f4437bbe95fd2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -670,7 +670,7 @@ def construct_return(result): else: return construct_return(result) - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: """ Return the values as a NumPy array. diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 2c7fc8b320325..bbcf53f107048 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -245,7 +245,7 @@ class ArrayLike: def __init__(self, array): self.array = array - def __array__(self, dtype=None): + def __array__(self, dtype=None) -> np.ndarray: return self.array expected = pd.Index(array)