From 89c324eb7db01c5663583699389bc90449f217bd Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 23 Mar 2020 13:38:08 -0700 Subject: [PATCH] CLN: remove unnecessary Series._convert calls --- pandas/core/generic.py | 8 +------- pandas/core/groupby/generic.py | 12 ++++-------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8c6a5c9d020b4..408a33bed25e1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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 @@ -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 ------- @@ -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) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 4102b8527b6aa..24704d5fc4d82 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -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 @@ -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) def _wrap_transformed_output( self, output: Mapping[base.OutputKey, Union[Series, np.ndarray]] @@ -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) # 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 @@ -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]]