-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
CLN: core/dtypes/cast.py::maybe_downcast_to_dtype #37050
CLN: core/dtypes/cast.py::maybe_downcast_to_dtype #37050
Conversation
pandas/core/dtypes/cast.py
Outdated
if dtype.kind in ["M", "m"] and result.dtype.kind in ["i", "f"]: | ||
if hasattr(dtype, "tz"): | ||
# GH12821, iNaT is cast to float | ||
if is_datetime_or_timedelta_any_dtype(dtype) and result.dtype.kind in ["i", "f"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the dtype.kind checks are much more performant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree, just leave this as is i think for L163 (and can remove the comment which isold)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok! Done both
pandas/core/dtypes/cast.py
Outdated
if dtype.kind in ["M", "m"] and result.dtype.kind in ["i", "f"]: | ||
if hasattr(dtype, "tz"): | ||
# GH12821, iNaT is cast to float | ||
if is_datetime_or_timedelta_any_dtype(dtype) and result.dtype.kind in ["i", "f"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree, just leave this as is i think for L163 (and can remove the comment which isold)
a5c9169
to
3aad776
Compare
pandas/core/dtypes/cast.py
Outdated
if dtype.kind in ["M", "m"] and result.dtype.kind in ["i", "f"]: | ||
if hasattr(dtype, "tz"): | ||
|
||
if is_datetime_or_timedelta_dtype(dtype): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this code here can be greatly simplified, see what the incoming inputs are and i bet you can adjust it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOW the way this is written L173 is always hit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried this. There are three tests that use the else block:
FAILED pandas/tests/dtypes/cast/test_downcast.py::test_datetime_with_timezone[True]
FAILED pandas/tests/frame/methods/test_combine_first.py::TestDataFrameCombineFirst::test_combine_first_timezone
FAILED pandas/tests/groupby/test_function.py::test_arg_passthru - TypeError: ...
Reverting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and you have L177. so i would revert to the original code here as well (except for the period change);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pandas/core/dtypes/cast.py
Outdated
if dtype.kind in ["M", "m"] and result.dtype.kind in ["i", "f"]: | ||
if hasattr(dtype, "tz"): | ||
|
||
if is_datetime_or_timedelta_dtype(dtype): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and you have L177. so i would revert to the original code here as well (except for the period change);
51557f4
to
e46b10d
Compare
thanks @arw2019 |
@arw2019 this solution could be to revert this and re-open? The mypy errors are
so i'm a bit reluctant to ignore to get mypy to green. The issue is related to #37024 (comment) so maybe only str and dtypeObj are accepted. so could also change to Union[str, DtypeObj] but this I think is unusual and should normally be DtypeObj or Dtype. |
This reverts commit fad14fd.
Your call since I'm still pretty new to the code base.
Again I'm fairly new but I think it's possible
For reference actually only use this method in a few places in the code:
|
we'll go with the revert for now even though the fix is straightfoward to allow unpressured discussion on the topic. OK with reopening this PR? |
Sounds good to me! |
…#37050)" (pandas-dev#37116) This reverts commit fad14fd.
…#37050)" (pandas-dev#37116) This reverts commit fad14fd.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff