-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: simplify maybe_convert_objects, soft_convert_objects #27444
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
Conversation
… unreachable branches
pandas/core/dtypes/cast.py
Outdated
|
||
else: | ||
values = lib.maybe_convert_objects(values, convert_datetime=convert_dates) | ||
if values.dtype == np.object_: |
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.
use is_object_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.
sure
pandas/core/dtypes/cast.py
Outdated
values = lib.maybe_convert_objects( | ||
values, convert_timedelta=convert_timedeltas | ||
) | ||
if values.dtype == np.object_: |
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.
same
@@ -2780,44 +2784,39 @@ def is_bool(self): | |||
return lib.is_bool_array(self.values.ravel()) | |||
|
|||
# TODO: Refactor when convert_objects is removed since there will be 1 path | |||
def convert(self, *args, **kwargs): | |||
def convert( |
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.
side issue is that a lot of this can be cleaned up now that convert_objects is gone
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 that deprecation was before I got here, so it isn't clear to me what else can be cleaned up
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.
maybe just remove the comment, you have cleaned up reasonably. you can try looking in history but if not ok.
numeric: bool = True, | ||
timedelta: bool = True, | ||
coerce: bool = False, | ||
): | ||
""" attempt to coerce any object types to better types return a copy of |
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.
add typing to the returns would be good here (and maybe Paramters / Returns to the doc-string), but can be in the future. I think adding doc-strings on routines that we are most likely going to keep is worth the effort (so use your judgement on this).
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.
lgtm. ping on green.
ping |
thanks |
Block.replace has code for dispatching to either maybe_convert_objects or soft_convert_objects, but the former is only reached from the tests. So rip that out and use soft_convert_objects.
Both of the functions have branches that are unreachable, so rip those out, along with adding types and validation.