Skip to content

CLN: core/dtypes/cast.py::maybe_casted_values #37183

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 1 commit into from
Oct 17, 2020
Merged
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
22 changes: 4 additions & 18 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,37 +491,23 @@ def maybe_casted_values(
if codes is not None:
mask: np.ndarray = codes == -1

# we can have situations where the whole mask is -1,
# meaning there is nothing found in codes, so make all nan's
if mask.size > 0 and mask.all():
# we can have situations where the whole mask is -1,
# meaning there is nothing found in codes, so make all nan's

dtype = index.dtype
fill_value = na_value_for_dtype(dtype)
values = construct_1d_arraylike_from_scalar(fill_value, len(mask), dtype)

else:
values = values.take(codes)

# TODO(https://github.com/pandas-dev/pandas/issues/24206)
# Push this into maybe_upcast_putmask?
# We can't pass EAs there right now. Looks a bit
# complicated.
# So we unbox the ndarray_values, op, re-box.
values_type = type(values)
values_dtype = values.dtype

from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin

if isinstance(values, DatetimeLikeArrayMixin):
values = values._data # TODO: can we de-kludge yet?

if mask.any():
if isinstance(values, np.ndarray):
values, _ = maybe_upcast_putmask(values, mask, np.nan)
else:
values[mask] = np.nan

if issubclass(values_type, DatetimeLikeArrayMixin):
values = values_type(values, dtype=values_dtype)

return values


Expand Down