10000 CLN: move maybe_casted_values from pandas/core/frame.py to pandas/core/dtype/cast.py by arw2019 · Pull Request #36985 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CLN: move maybe_casted_values from pandas/core/frame.py to pandas/core/dtype/cast.py #36985

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 9 commits into from
Oct 10, 2020
Prev Previous commit
Next Next commit
add DatetimeLikeArrayMixin import in maybe_casted_values
  • Loading branch information
arw2019 committed Oct 10, 2020
commit 3cce7057b27c0678e78a181356aa8effd102806c
6 changes: 4 additions & 2 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,15 @@ def maybe_casted_values(index, codes=None):
values_type = type(values)
values_dtype = values.dtype

if issubclass(values_type, ABCDatetimeArray):
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is acceptable - will change if not. The issue is we can't just import at the top of the file because of a circular import

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do needs_i8_conversion(values.dtype) and isinstance(values, ExtensionArray)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok fine with cleaning this up after, this routine definitely needs it (and also possibly is duplicative of things in this file anyways)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do needs_i8_conversion(values.dtype) and isinstance(values, ExtensionArray)

tried it and it broke some tests. I'll investigate in the follow-on


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

if mask.any():
values, _ = maybe_upcast_putmask(values, mask, np.nan)

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

return values
Expand Down
0