Skip to content

CLN: avoid incorrect usages of values_for_argsort #37824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ def __getitem__(self, key):
# ---------------------------------------------------------------------

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

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

_data: NDArrayBackedExtensionArray

def _get_engine_target(self) -> np.ndarray:
return self._data._ndarray

def delete(self, loc):
"""
Make new Index with passed location(-s) deleted
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def is_na(self) -> bool:

return isna_all(values_flat)

def get_reindexed_values(self, empty_dtype, upcasted_na):
def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na):
if upcasted_na is None:
# No upcasting is necessary
fill_value = self.block.fill_value
Expand All @@ -248,9 +248,8 @@ def get_reindexed_values(self, empty_dtype, upcasted_na):
empty_dtype
):
if self.block is None:
array = empty_dtype.construct_array_type()
# TODO(EA2D): special case unneeded with 2D EAs
return array(
return DatetimeArray(
np.full(self.shape[1], fill_value.value), dtype=empty_dtype
)
elif getattr(self.block, "is_categorical", False):
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import datetime
from functools import partial
import string
from typing import TYPE_CHECKING, Optional, Tuple
from typing import TYPE_CHECKING, Optional, Tuple, cast
import warnings

import numpy as np
Expand Down Expand Up @@ -50,6 +50,7 @@

if TYPE_CHECKING:
from pandas import DataFrame
from pandas.core.arrays import DatetimeArray


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

elif (
is_categorical_dtype(lk.dtype)
Expand Down