|
19 | 19 | the versions in the later versions of pandas. |
20 | 20 | """ |
21 | 21 |
|
22 | | -from typing import Any |
23 | | - |
24 | | -import numpy |
25 | 22 | import packaging.version |
26 | 23 | import pandas |
27 | | -from pandas.api.types import is_integer |
28 | 24 | import pandas.compat.numpy.function |
29 | | -import pandas.core.nanops |
30 | 25 |
|
31 | 26 | pandas_release = packaging.version.parse(pandas.__version__).release |
32 | 27 |
|
33 | | -# Create aliases for private methods in case they move in a future version. |
| 28 | +# # Create aliases for private methods in case they move in a future version. |
34 | 29 | nanall = pandas.core.nanops.nanall |
35 | 30 | nanany = pandas.core.nanops.nanany |
36 | 31 | nanmax = pandas.core.nanops.nanmax |
|
40 | 35 | numpy_validate_max = pandas.compat.numpy.function.validate_max |
41 | 36 | numpy_validate_min = pandas.compat.numpy.function.validate_min |
42 | 37 |
|
43 | | -if pandas_release >= (1, 3): |
44 | | - nanmedian = pandas.core.nanops.nanmedian |
45 | | - numpy_validate_median = pandas.compat.numpy.function.validate_median |
| 38 | +nanmedian = pandas.core.nanops.nanmedian |
| 39 | +numpy_validate_median = pandas.compat.numpy.function.validate_median |
46 | 40 |
|
47 | 41 |
|
48 | 42 | def import_default(module_name, force=False, default=None): |
@@ -78,83 +72,3 @@ def import_default(module_name, force=False, default=None): |
78 | 72 | class OpsMixin: |
79 | 73 | def _cmp_method(self, other, op): # pragma: NO COVER |
80 | 74 | return NotImplemented |
81 | | - |
82 | | - |
83 | | -# TODO: use public API once pandas 1.5 / 2.x is released. |
84 | | -# See: https://github.com/pandas-dev/pandas/pull/45544 |
85 | | -@import_default("pandas.core.arrays._mixins", pandas_release < (1, 3)) |
86 | | -class NDArrayBackedExtensionArray(pandas.core.arrays.base.ExtensionArray): |
87 | | - def __init__(self, values, dtype): |
88 | | - assert isinstance(values, numpy.ndarray) |
89 | | - self._ndarray = values |
90 | | - self._dtype = dtype |
91 | | - |
92 | | - @classmethod |
93 | | - def _from_backing_data(cls, data): |
94 | | - return cls(data, data.dtype) |
95 | | - |
96 | | - def __getitem__(self, index): |
97 | | - value = self._ndarray[index] |
98 | | - if is_integer(index): |
99 | | - return self._box_func(value) |
100 | | - return self.__class__(value, self._dtype) |
101 | | - |
102 | | - def __setitem__(self, index, value): |
103 | | - self._ndarray[index] = self._validate_setitem_value(value) |
104 | | - |
105 | | - def __len__(self): |
106 | | - return len(self._ndarray) |
107 | | - |
108 | | - @property |
109 | | - def shape(self): |
110 | | - return self._ndarray.shape |
111 | | - |
112 | | - @property |
113 | | - def ndim(self) -> int: |
114 | | - return self._ndarray.ndim |
115 | | - |
116 | | - @property |
117 | | - def size(self) -> int: |
118 | | - return self._ndarray.size |
119 | | - |
120 | | - @property |
121 | | - def nbytes(self) -> int: |
122 | | - return self._ndarray.nbytes |
123 | | - |
124 | | - def copy(self): |
125 | | - return self[:] |
126 | | - |
127 | | - def repeat(self, n): |
128 | | - return self.__class__(self._ndarray.repeat(n), self._dtype) |
129 | | - |
130 | | - def take( |
131 | | - self, |
132 | | - indices, |
133 | | - *, |
134 | | - allow_fill: bool = False, |
135 | | - fill_value: Any = None, |
136 | | - axis: int = 0, |
137 | | - ): |
138 | | - from pandas.core.algorithms import take |
139 | | - |
140 | | - if allow_fill: |
141 | | - fill_value = self._validate_scalar(fill_value) |
142 | | - |
143 | | - new_data = take( |
144 | | - self._ndarray, |
145 | | - indices, |
146 | | - allow_fill=allow_fill, |
147 | | - fill_value=fill_value, |
148 | | - axis=axis, |
149 | | - ) |
150 | | - return self._from_backing_data(new_data) |
151 | | - |
152 | | - @classmethod |
153 | | - def _concat_same_type(cls, to_concat, axis=0): |
154 | | - dtypes = {str(x.dtype) for x in to_concat} |
155 | | - if len(dtypes) != 1: |
156 | | - raise ValueError("to_concat must have the same dtype (tz)", dtypes) |
157 | | - |
158 | | - new_values = [x._ndarray for x in to_concat] |
159 | | - new_values = numpy.concatenate(new_values, axis=axis) |
160 | | - return to_concat[0]._from_backing_data(new_values) # type: ignore[arg-type] |
0 commit comments