Skip to content

CLN: remove unnecessary Series._convert calls #32949

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
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 7 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5700,7 +5700,6 @@ def _convert(
numeric: bool_t = False,
timedelta: bool_t = False,
coerce: bool_t = False,
copy: bool_t = True,
) -> FrameOrSeries:
"""
Attempt to infer better dtype for object columns
Expand All @@ -5717,10 +5716,6 @@ def _convert(
coerce : bool, default False
If True, force conversion with unconvertible values converted to
nulls (NaN or NaT).
copy : bool, default True
If True, return a copy even if no copy is necessary (e.g. no
conversion was done). Note: This is meant for internal use, and
should not be confused with inplace.

Returns
-------
Expand All @@ -5730,14 +5725,13 @@ def _convert(
validate_bool_kwarg(numeric, "numeric")
validate_bool_kwarg(timedelta, "timedelta")
validate_bool_kwarg(coerce, "coerce")
validate_bool_kwarg(copy, "copy")
return self._constructor(
self._data.convert(
datetime=datetime,
numeric=numeric,
timedelta=timedelta,
coerce=coerce,
copy=copy,
copy=True,
)
).__finalize__(self)

Expand Down
12 changes: 4 additions & 8 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import numpy as np

from pandas._libs import Timestamp, lib
from pandas._libs import lib
from pandas._typing import FrameOrSeries
from pandas.util._decorators import Appender, Substitution

Expand Down Expand Up @@ -386,7 +386,7 @@ def _wrap_aggregated_output(
result = self._wrap_series_output(
output=output, index=self.grouper.result_index
)
return self._reindex_output(result)._convert(datetime=True)
return self._reindex_output(result)
Copy link
Member

Choose a reason for hiding this comment

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

Do you have an explanation of why this is not needed anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, just an observation that we dont have any tests that break without it.


def _wrap_transformed_output(
self, output: Mapping[base.OutputKey, Union[Series, np.ndarray]]
Expand Down Expand Up @@ -1342,14 +1342,10 @@ def first_not_none(values):

# values are not series or array-like but scalars
else:
# only coerce dates if we find at least 1 datetime
should_coerce = any(isinstance(x, Timestamp) for x in values)
Copy link
Member

Choose a reason for hiding this comment

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

Does this change behaviour?

# self._selection_name not passed through to Series as the
# result should not take the name of original selection
# of columns
return Series(values, index=key_index)._convert(
datetime=True, coerce=should_coerce
)
return Series(values, index=key_index)

else:
# Handle cases like BinGrouper
Expand Down Expand Up @@ -1699,7 +1695,7 @@ def _wrap_aggregated_output(
if self.axis == 1:
result = result.T

return self._reindex_output(result)._convert(datetime=True)
return self._reindex_output(result)

def _wrap_transformed_output(
self, output: Mapping[base.OutputKey, Union[Series, np.ndarray]]
Expand Down