Skip to content

Commit 524fc9c

Browse files
authored
CLN: avoid incorrect usages of values_for_argsort (pandas-dev#37824)
1 parent be03eb1 commit 524fc9c

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

pandas/core/indexes/extension.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,7 @@ def __getitem__(self, key):
231231
# ---------------------------------------------------------------------
232232

233233
def _get_engine_target(self) -> np.ndarray:
234-
# NB: _values_for_argsort happens to match the desired engine targets
235-
# for all of our existing EA-backed indexes, but in general
236-
# cannot be relied upon to exist.
237-
return self._data._values_for_argsort()
234+
return np.asarray(self._data)
238235

239236
def repeat(self, repeats, axis=None):
240237
nv.validate_repeat(tuple(), dict(axis=axis))
@@ -306,6 +303,9 @@ class NDArrayBackedExtensionIndex(ExtensionIndex):
306303

307304
_data: NDArrayBackedExtensionArray
308305

306+
def _get_engine_target(self) -> np.ndarray:
307+
return self._data._ndarray
308+
309309
def delete(self, loc):
310310
"""
311311
Make new Index with passed location(-s) deleted

pandas/core/internals/concat.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def is_na(self) -> bool:
227227

228228
return isna_all(values_flat)
229229

230-
def get_reindexed_values(self, empty_dtype, upcasted_na):
230+
def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na):
231231
if upcasted_na is None:
232232
# No upcasting is necessary
233233
fill_value = self.block.fill_value
@@ -248,9 +248,8 @@ def get_reindexed_values(self, empty_dtype, upcasted_na):
248248
empty_dtype
249249
):
250250
if self.block is None:
251-
array = empty_dtype.construct_array_type()
252251
# TODO(EA2D): special case unneeded with 2D EAs
253-
return array(
252+
return DatetimeArray(
254253
np.full(self.shape[1], fill_value.value), dtype=empty_dtype
255254
)
256255
elif getattr(self.block, "is_categorical", False):

pandas/core/reshape/merge.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import datetime
77
from functools import partial
88
import string
9-
from typing import TYPE_CHECKING, Optional, Tuple
9+
from typing import TYPE_CHECKING, Optional, Tuple, cast
1010
import warnings
1111

1212
import numpy as np
@@ -50,6 +50,7 @@
5050

5151
if TYPE_CHECKING:
5252
from pandas import DataFrame
53+
from pandas.core.arrays import DatetimeArray
5354

5455

5556
@Substitution("\nleft : DataFrame")
@@ -1947,8 +1948,8 @@ def _factorize_keys(
19471948
if is_datetime64tz_dtype(lk.dtype) and is_datetime64tz_dtype(rk.dtype):
19481949
# Extract the ndarray (UTC-localized) values
19491950
# Note: we dont need the dtypes to match, as these can still be compared
1950-
lk, _ = lk._values_for_factorize()
1951-
rk, _ = rk._values_for_factorize()
1951+
lk = cast("DatetimeArray", lk)._ndarray
1952+
rk = cast("DatetimeArray", rk)._ndarray
19521953

19531954
elif (
19541955
is_categorical_dtype(lk.dtype)

0 commit comments

Comments
 (0)