Skip to content

Commit be86b65

Browse files
authored
CLN: remove unnecessary Series._convert calls (#32949)
1 parent 4334482 commit be86b65

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

pandas/core/generic.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -5709,7 +5709,6 @@ def _convert(
57095709
numeric: bool_t = False,
57105710
timedelta: bool_t = False,
57115711
coerce: bool_t = False,
5712-
copy: bool_t = True,
57135712
) -> FrameOrSeries:
57145713
"""
57155714
Attempt to infer better dtype for object columns
@@ -5726,10 +5725,6 @@ def _convert(
57265725
coerce : bool, default False
57275726
If True, force conversion with unconvertible values converted to
57285727
nulls (NaN or NaT).
5729-
copy : bool, default True
5730-
If True, return a copy even if no copy is necessary (e.g. no
5731-
conversion was done). Note: This is meant for internal use, and
5732-
should not be confused with inplace.
57335728
57345729
Returns
57355730
-------
@@ -5739,14 +5734,13 @@ def _convert(
57395734
validate_bool_kwarg(numeric, "numeric")
57405735
validate_bool_kwarg(timedelta, "timedelta")
57415736
validate_bool_kwarg(coerce, "coerce")
5742-
validate_bool_kwarg(copy, "copy")
57435737
return self._constructor(
57445738
self._mgr.convert(
57455739
datetime=datetime,
57465740
numeric=numeric,
57475741
timedelta=timedelta,
57485742
coerce=coerce,
5749-
copy=copy,
5743+
copy=True,
57505744
)
57515745
).__finalize__(self)
57525746

pandas/core/groupby/generic.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import numpy as np
3131

32-
from pandas._libs import Timestamp, lib
32+
from pandas._libs import lib
3333
from pandas._typing import FrameOrSeries
3434
from pandas.util._decorators import Appender, Substitution, doc
3535

@@ -388,7 +388,7 @@ def _wrap_aggregated_output(
388388
result = self._wrap_series_output(
389389
output=output, index=self.grouper.result_index
390390
)
391-
return self._reindex_output(result)._convert(datetime=True)
391+
return self._reindex_output(result)
392392

393393
def _wrap_transformed_output(
394394
self, output: Mapping[base.OutputKey, Union[Series, np.ndarray]]
@@ -1346,14 +1346,10 @@ def first_not_none(values):
13461346

13471347
# values are not series or array-like but scalars
13481348
else:
1349-
# only coerce dates if we find at least 1 datetime
1350-
should_coerce = any(isinstance(x, Timestamp) for x in values)
13511349
# self._selection_name not passed through to Series as the
13521350
# result should not take the name of original selection
13531351
# of columns
1354-
return Series(values, index=key_index)._convert(
1355-
datetime=True, coerce=should_coerce
1356-
)
1352+
return Series(values, index=key_index)
13571353

13581354
else:
13591355
# Handle cases like BinGrouper
@@ -1703,7 +1699,7 @@ def _wrap_aggregated_output(
17031699
if self.axis == 1:
17041700
result = result.T
17051701

1706-
return self._reindex_output(result)._convert(datetime=True)
1702+
return self._reindex_output(result)
17071703

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

0 commit comments

Comments
 (0)