|
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
|
@@ -77,89 +72,3 @@ def import_default(module_name, force=False, default=None):
|
77 | 72 | class OpsMixin:
|
78 | 73 | def _cmp_method(self, other, op): # pragma: NO COVER
|
79 | 74 | return NotImplemented
|
80 |
| - |
81 |
| - |
82 |
| -# TODO: use public API once NDArrayBackedExtensionArray is added to the |
83 |
| -# pandas. |
84 |
| -# See: https://github.com/pandas-dev/pandas/pull/45544 |
85 |
| -# Also: Right now none of this is tested in test_pandas_backports. |
86 |
| -# Temporarily marking this as # pragma: NO COVER just to see how this |
87 |
| -# affects unittest coverage |
88 |
| -@import_default("pandas.core.arrays._mixins") |
89 |
| -class NDArrayBackedExtensionArray( |
90 |
| - pandas.core.arrays.base.ExtensionArray |
91 |
| -): # pragma: NO COVER |
92 |
| - def __init__(self, values, dtype): |
93 |
| - assert isinstance(values, numpy.ndarray) |
94 |
| - self._ndarray = values |
95 |
| - self._dtype = dtype |
96 |
| - |
97 |
| - @classmethod |
98 |
| - def _from_backing_data(cls, data): |
99 |
| - return cls(data, data.dtype) |
100 |
| - |
101 |
| - def __getitem__(self, index): |
102 |
| - value = self._ndarray[index] |
103 |
| - if is_integer(index): |
104 |
| - return self._box_func(value) |
105 |
| - return self.__class__(value, self._dtype) |
106 |
| - |
107 |
| - def __setitem__(self, index, value): |
108 |
| - self._ndarray[index] = self._validate_setitem_value(value) |
109 |
| - |
110 |
| - def __len__(self): |
111 |
| - return len(self._ndarray) |
112 |
| - |
113 |
| - @property |
114 |
| - def shape(self): |
115 |
| - return self._ndarray.shape |
116 |
| - |
117 |
| - @property |
118 |
| - def ndim(self) -> int: |
119 |
| - return self._ndarray.ndim |
120 |
| - |
121 |
| - @property |
122 |
| - def size(self) -> int: |
123 |
| - return self._ndarray.size |
124 |
| - |
125 |
| - @property |
126 |
| - def nbytes(self) -> int: |
127 |
| - return self._ndarray.nbytes |
128 |
| - |
129 |
| - def copy(self): |
130 |
| - return self[:] |
131 |
| - |
132 |
| - def repeat(self, n): |
133 |
| - return self.__class__(self._ndarray.repeat(n), self._dtype) |
134 |
| - |
135 |
| - def take( |
136 |
| - self, |
137 |
| - indices, |
138 |
| - *, |
139 |
| - allow_fill: bool = False, |
140 |
| - fill_value: Any = None, |
141 |
| - axis: int = 0, |
142 |
| - ): |
143 |
| - from pandas.core.algorithms import take |
144 |
| - |
145 |
| - if allow_fill: |
146 |
| - fill_value = self._validate_scalar(fill_value) |
147 |
| - |
148 |
| - new_data = take( |
149 |
| - self._ndarray, |
150 |
| - indices, |
151 |
| - allow_fill=allow_fill, |
152 |
| - fill_value=fill_value, |
153 |
| - axis=axis, |
154 |
| - ) |
155 |
| - return self._from_backing_data(new_data) |
156 |
| - |
157 |
| - @classmethod |
158 |
| - def _concat_same_type(cls, to_concat, axis=0): |
159 |
| - dtypes = {str(x.dtype) for x in to_concat} |
160 |
| - if len(dtypes) != 1: |
161 |
| - raise ValueError("to_concat must have the same dtype (tz)", dtypes) |
162 |
| - |
163 |
| - new_values = [x._ndarray for x in to_concat] |
164 |
| - new_values = numpy.concatenate(new_values, axis=axis) |
165 |
| - return to_concat[0]._from_backing_data(new_values) # type: ignore[arg-type] |
0 commit comments