@@ -155,83 +155,6 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike:
155155 # "ExtensionDtype | dtype[Any]"; expected "dtype[Any] | _HasDType[dtype[Any]]"
156156 return arr .view (dtype = dtype ) # type: ignore[arg-type]
157157
158-
159- # Notes on take method fix
160- # Please remove these once this fix is ready to submit.
161- # =======================================================================
162-
163- # One of the base classes to this class: ExtensionArray, provides
164- # the dtype property, but abstractly, so it leaves the implementation
165- # of dtype storage up to its derived classes. Some of these derived
166- # classes don't provide a setter method for their dtype property, so
167- # I can't set the dtype here and expect it to work for all classes that
168- # inherit this take method.
169-
170- # How can I produce an extension array of the same type as self,
171- # having a floating-point dtype if self has an integer dtype or otherwise
172- # the same dtype as self?
173-
174- # Constructing a new object of the same type as self doesn't always
175- # work since the constructors of some derived classes of this class
176- # don't accept a dtype parameter, which I need to pass to set the
177- # result's dtype to a floating-point type.
178-
179- # All tests pass when I create a new extension array object with the
180- # appropriate dtype (in the integer-dtype source case), however MyPy
181- # complains about the missing dtype argument in the call to type(self)
182- # below. By creating a new array object, this call produces an array
183- # with a floating point dtype, even when the source dtype is integral.
184- # I think this happens because the new array is created with the newly
185- # produced data from the underlying take method, which has the
186- # appropriate underlying dtype.
187-
188- # Essentially, these extension arrays are wrappers around Numpy arrays
189- # which have their own dtype and store the data. Thus, the new
190- # extension array inherits the dtype from the Numpy array used
191- # to create it.
192-
193- # Unfortunately, some of the derived constructors of this class have a
194- # positional dtype argument, while some do not. If I call a constructor
195- # without specifying this argument, mypy will complain about the
196- # missing argument in the case of constructors that require it, but
197- # if I call the constructor with the dtype argument, the constructors
198- # that don't have it will fail at runtime since they don't recognize
199- # it.
200-
201- # How can I get around this issue?
202- # Ideas:
203- # Modify the extension array type to allow modification of its dtype
204- # after construction.
205-
206- # Add a conditional branch to this method to call derived constructors
207- # with or without the dtype argument, depending on their class.
208- # This approach has the disadvantage of hardcoding information about
209- # derived classes in this base class, which means that if someone
210- # changes a constructor of a derived class to remove the dtype argument,
211- # this method will break.
212-
213- # Classes derived from this class include:
214-
215- # Categorical
216- # DatetimeLikeArrayMixin
217- # DatelikeOps
218- # PeriodArray
219- # DatetimeArray
220- # TimelikeOps
221- # TimedeltaArray
222- # NumpyExtensionArray
223- # StringArray
224-
225- # The types of extension arrays (within Pandas) derived from this class are:
226- # Class name Constructor takes dtype argument Dtype argument required
227- # Categorical yes no
228- # PeriodArray yes no
229- # DatetimeArray
230- # TimedeltaArray
231- # StringArray yes no
232- # NumpyExtensionArray no no
233-
234-
235158 def take (
236159 self ,
237160 indices : TakeIndexer ,
0 commit comments