From b1085e1e91a0e477365188fb430521e171d5972c Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 15:17:45 +0530 Subject: [PATCH 01/12] t1 --- pandas/core/generic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b90833bda82b5..13462f5beb03a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2,9 +2,8 @@ from __future__ import annotations import collections -from datetime import timedelta +from datetime import timedelta as td import gc -import json import operator import pickle import re @@ -133,7 +132,7 @@ from pandas.core import ( algorithms as algos, arraylike, - common as com, + common, indexing, missing, nanops, @@ -6318,6 +6317,7 @@ def _convert( self: NDFrameT, datetime: bool_t = False, numeric: bool_t = False, + # td: bool_t = False, timedelta: bool_t = False, ) -> NDFrameT: """ @@ -11538,7 +11538,7 @@ def ewm( axis = self._get_axis_number(axis) return ExponentialMovingWindow( self, - com=com, + com=commmon, span=span, halflife=halflife, alpha=alpha, From 72adf831f7e73868ce833726b46ef245af445d5f Mon Sep 17 00:00:00 2001 From: ram vikram singh Date: Tue, 15 Nov 2022 16:35:33 +0530 Subject: [PATCH 02/12] update --- pandas/core/generic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 13462f5beb03a..df88c21c03e3b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2,7 +2,7 @@ from __future__ import annotations import collections -from datetime import timedelta as td +from datetime ad dt import gc import operator import pickle @@ -132,12 +132,12 @@ from pandas.core import ( algorithms as algos, arraylike, - common, indexing, missing, nanops, sample, ) +from pandas.core.common import get_rename_function as com from pandas.core.array_algos.replace import should_use_regex from pandas.core.arrays import ExtensionArray from pandas.core.base import PandasObject @@ -6318,7 +6318,7 @@ def _convert( datetime: bool_t = False, numeric: bool_t = False, # td: bool_t = False, - timedelta: bool_t = False, + dt.timedelta: bool_t = False, ) -> NDFrameT: """ Attempt to infer better dtype for object columns. @@ -11538,7 +11538,7 @@ def ewm( axis = self._get_axis_number(axis) return ExponentialMovingWindow( self, - com=commmon, + com=com, span=span, halflife=halflife, alpha=alpha, From bb32416bffe69273be4568414a12e3beb63e8f43 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 17:00:54 +0530 Subject: [PATCH 03/12] update --- pandas/core/generic.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index df88c21c03e3b..4c08dca1c449e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2,7 +2,7 @@ from __future__ import annotations import collections -from datetime ad dt +import datetime as dt import gc import operator import pickle @@ -137,7 +137,15 @@ nanops, sample, ) -from pandas.core.common import get_rename_function as com +from pandas.core.common import ( + pipe, + random_state, + count_not_none, + maybe_make_list, + apply_if_callable, + index_labels_to_array, + get_rename_function, +) from pandas.core.array_algos.replace import should_use_regex from pandas.core.arrays import ExtensionArray from pandas.core.base import PandasObject @@ -1008,7 +1016,7 @@ def _rename( continue ax = self._get_axis(axis_no) - f = com.get_rename_function(replacements) + f = get_rename_function(replacements) if level is not None: level = ax._get_level_number(level) @@ -1239,7 +1247,7 @@ class name if non_mapper: newnames = v else: - f = com.get_rename_function(v) + f = get_rename_function(v) curnames = self._get_axis(axis).names newnames = [f(name) for name in curnames] result._set_axis_name(newnames, axis=axis, inplace=True) @@ -1825,7 +1833,7 @@ def _drop_labels_or_levels(self, keys, axis: AxisInt = 0): axis = self._get_axis_number(axis) # Validate keys - keys = com.maybe_make_list(keys) + keys = maybe_make_list(keys) invalid_keys = [ k for k in keys if not self._is_label_or_level_reference(k, axis=axis) ] @@ -4444,7 +4452,7 @@ def _drop_axis( # Case for non-unique axis else: is_tuple_labels = is_nested_list_like(labels) or isinstance(labels, tuple) - labels = ensure_object(com.index_labels_to_array(labels)) + labels = ensure_object(index_labels_to_array(labels)) if level is not None: if not isinstance(axis, MultiIndex): raise AssertionError("axis must be a MultiIndex") @@ -5235,7 +5243,7 @@ def _reindex_axes( def _needs_reindex_multi(self, axes, method, level) -> bool_t: """Check if we do need a multi reindex.""" return ( - (com.count_not_none(*axes.values()) == self._AXIS_LEN) + (count_not_none(*axes.values()) == self._AXIS_LEN) and method is None and level is None and not self._is_mixed_type @@ -5358,7 +5366,7 @@ def filter( one two three rabbit 4 5 6 """ - nkw = com.count_not_none(items, like, regex) + nkw = count_not_none(items, like, regex) if nkw > 1: raise TypeError( "Keyword arguments `items`, `like`, or `regex` " @@ -5683,7 +5691,7 @@ def sample( obj_len = self.shape[axis] # Process random_state argument - rs = com.random_state(random_state) + rs = random_state(random_state) size = sample.process_sampling_size(n, frac, replace) if size is None: @@ -5759,7 +5767,7 @@ def pipe( ... .pipe((func, 'arg2'), arg1=a, arg3=c) ... ) # doctest: +SKIP """ - return com.pipe(self, func, *args, **kwargs) + return pipe(self, func, *args, **kwargs) # ---------------------------------------------------------------------- # Attribute access @@ -6317,8 +6325,7 @@ def _convert( self: NDFrameT, datetime: bool_t = False, numeric: bool_t = False, - # td: bool_t = False, - dt.timedelta: bool_t = False, + timedelta: bool_t = False, ) -> NDFrameT: """ Attempt to infer better dtype for object columns. @@ -9445,7 +9452,7 @@ def _where( axis = self._get_axis_number(axis) # align the cond to same shape as myself - cond = com.apply_if_callable(cond, self) + cond = apply_if_callable(cond, self) if isinstance(cond, NDFrame): cond, _ = cond.align(self, join="right", broadcast_axis=1, copy=False) else: @@ -9747,7 +9754,7 @@ def where( 3 True True 4 True True """ - other = com.apply_if_callable(other, self) + other = apply_if_callable(other, self) return self._where(cond, other, inplace, axis, level) @overload @@ -9805,7 +9812,7 @@ def mask( ) -> NDFrameT | None: inplace = validate_bool_kwarg(inplace, "inplace") - cond = com.apply_if_callable(cond, self) + cond = apply_if_callable(cond, self) # see gh-21891 if not hasattr(cond, "__invert__"): From 7b9a906a1f85ce52c66d2df26ee944170f476427 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 20:06:41 +0530 Subject: [PATCH 04/12] Update generic.py --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4c08dca1c449e..1b132a974c88c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10324,7 +10324,7 @@ def tz_localize( """ nonexistent_options = ("raise", "NaT", "shift_forward", "shift_backward") if nonexistent not in nonexistent_options and not isinstance( - nonexistent, timedelta + nonexistent, dt.timedelta ): raise ValueError( "The nonexistent argument must be one of 'raise', " From 4cc4707d078fc72039dcc34184ba16fa85bb1404 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 20:36:33 +0530 Subject: [PATCH 05/12] update --- pandas/core/generic.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1b132a974c88c..ed1c687cf3417 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -31,6 +31,7 @@ from pandas._config import config from pandas._libs import lib +from pandas._libs import json from pandas._libs.tslibs import ( Period, Tick, @@ -138,13 +139,12 @@ sample, ) from pandas.core.common import ( - pipe, - random_state, - count_not_none, - maybe_make_list, apply_if_callable, - index_labels_to_array, + count_not_none, get_rename_function, + index_labels_to_array, + maybe_make_list, + pipe, ) from pandas.core.array_algos.replace import should_use_regex from pandas.core.arrays import ExtensionArray @@ -6351,7 +6351,7 @@ def _convert( self._mgr.convert( datetime=datetime, numeric=numeric, - timedelta=timedelta, + timedelta=dt.timedelta, copy=True, ) ).__finalize__(self) @@ -10324,7 +10324,7 @@ def tz_localize( """ nonexistent_options = ("raise", "NaT", "shift_forward", "shift_backward") if nonexistent not in nonexistent_options and not isinstance( - nonexistent, dt.timedelta + nonexistent, timedelta ): raise ValueError( "The nonexistent argument must be one of 'raise', " @@ -11477,7 +11477,7 @@ def min( @doc(Rolling) def rolling( self, - window: int | timedelta | str | BaseOffset | BaseIndexer, + window: int | dt.timedelta | str | BaseOffset | BaseIndexer, min_periods: int | None = None, center: bool_t = False, win_type: str | None = None, From c271579d0f8920a6bc99a435de0cf8ebe0012d77 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 20:49:06 +0530 Subject: [PATCH 06/12] Update generic.py --- pandas/core/generic.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ed1c687cf3417..de157b464b120 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -30,8 +30,10 @@ from pandas._config import config -from pandas._libs import lib -from pandas._libs import json +from pandas._libs import ( + json, + lib, +) from pandas._libs.tslibs import ( Period, Tick, @@ -138,6 +140,9 @@ nanops, sample, ) +from pandas.core.array_algos.replace import should_use_regex +from pandas.core.arrays import ExtensionArray +from pandas.core.base import PandasObject from pandas.core.common import ( apply_if_callable, count_not_none, @@ -146,9 +151,6 @@ maybe_make_list, pipe, ) -from pandas.core.array_algos.replace import should_use_regex -from pandas.core.arrays import ExtensionArray -from pandas.core.base import PandasObject from pandas.core.construction import extract_array from pandas.core.describe import describe_ndframe from pandas.core.flags import Flags From f39a955d6f97749ccbb553606d91d75ef3b959ce Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 21:08:14 +0530 Subject: [PATCH 07/12] Update generic.py --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index de157b464b120..bc7d2fcb27462 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10326,7 +10326,7 @@ def tz_localize( """ nonexistent_options = ("raise", "NaT", "shift_forward", "shift_backward") if nonexistent not in nonexistent_options and not isinstance( - nonexistent, timedelta + nonexistent, dt.timedelta ): raise ValueError( "The nonexistent argument must be one of 'raise', " From 625960a575e0561f3adcf2bb16b8ca36ddbe7f92 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 21:14:59 +0530 Subject: [PATCH 08/12] Update generic.py --- pandas/core/generic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index bc7d2fcb27462..f502b56da3819 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2,7 +2,7 @@ from __future__ import annotations import collections -import datetime as dt +import datetime as _dt import gc import operator import pickle @@ -143,7 +143,7 @@ from pandas.core.array_algos.replace import should_use_regex from pandas.core.arrays import ExtensionArray from pandas.core.base import PandasObject -from pandas.core.common import ( +from pandas.core.common import ( # noqa: PDF018 apply_if_callable, count_not_none, get_rename_function, @@ -6353,7 +6353,7 @@ def _convert( self._mgr.convert( datetime=datetime, numeric=numeric, - timedelta=dt.timedelta, + timedelta=_dt.timedelta, copy=True, ) ).__finalize__(self) @@ -10326,7 +10326,7 @@ def tz_localize( """ nonexistent_options = ("raise", "NaT", "shift_forward", "shift_backward") if nonexistent not in nonexistent_options and not isinstance( - nonexistent, dt.timedelta + nonexistent, _dt.timedelta ): raise ValueError( "The nonexistent argument must be one of 'raise', " @@ -11479,7 +11479,7 @@ def min( @doc(Rolling) def rolling( self, - window: int | dt.timedelta | str | BaseOffset | BaseIndexer, + window: int | _dt.timedelta | str | BaseOffset | BaseIndexer, min_periods: int | None = None, center: bool_t = False, win_type: str | None = None, From d0e36dd7bc2b4b049ca850e6e212f230b24b779f Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 21:23:01 +0530 Subject: [PATCH 09/12] Update generic.py --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f502b56da3819..e8614e1e9cf98 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -143,7 +143,7 @@ from pandas.core.array_algos.replace import should_use_regex from pandas.core.arrays import ExtensionArray from pandas.core.base import PandasObject -from pandas.core.common import ( # noqa: PDF018 +from pandas.core.common import ( # noqa: PDF018 apply_if_callable, count_not_none, get_rename_function, From 63b6458ca716a0ecc28020cf0ddbdbc316429b66 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 22:02:36 +0530 Subject: [PATCH 10/12] Update generic.py --- pandas/core/generic.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e8614e1e9cf98..672a7ababd993 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2,7 +2,7 @@ from __future__ import annotations import collections -import datetime as _dt +import datetime as dt import gc import operator import pickle @@ -6353,7 +6353,7 @@ def _convert( self._mgr.convert( datetime=datetime, numeric=numeric, - timedelta=_dt.timedelta, + timedelta=dt.timedelta, copy=True, ) ).__finalize__(self) @@ -9476,9 +9476,9 @@ def _where( if not is_bool_dtype(cond): raise ValueError(msg.format(dtype=cond.dtype)) else: - for dt in cond.dtypes: - if not is_bool_dtype(dt): - raise ValueError(msg.format(dtype=dt)) + for _dt in cond.dtypes: + if not is_bool_dtype(_dt): + raise ValueError(msg.format(dtype=_dt)) else: # GH#21947 we have an empty DataFrame/Series, could be object-dtype cond = cond.astype(bool) @@ -10326,7 +10326,7 @@ def tz_localize( """ nonexistent_options = ("raise", "NaT", "shift_forward", "shift_backward") if nonexistent not in nonexistent_options and not isinstance( - nonexistent, _dt.timedelta + nonexistent, dt.timedelta ): raise ValueError( "The nonexistent argument must be one of 'raise', " @@ -11479,7 +11479,7 @@ def min( @doc(Rolling) def rolling( self, - window: int | _dt.timedelta | str | BaseOffset | BaseIndexer, + window: int | dt.timedelta | str | BaseOffset | BaseIndexer, min_periods: int | None = None, center: bool_t = False, win_type: str | None = None, From 8208ce70923d2780ecd161b88de8d8073608188a Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 23:17:31 +0530 Subject: [PATCH 11/12] Update generic.py --- pandas/core/generic.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 672a7ababd993..f8d61cd1e654b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -30,10 +30,8 @@ from pandas._config import config -from pandas._libs import ( - json, - lib, -) +from pandas._libs import lib +import json from pandas._libs.tslibs import ( Period, Tick, @@ -132,6 +130,7 @@ notna, ) +from pandas.core import common # noqa: PDF018 from pandas.core import ( algorithms as algos, arraylike, @@ -6353,7 +6352,7 @@ def _convert( self._mgr.convert( datetime=datetime, numeric=numeric, - timedelta=dt.timedelta, + timedelta=timedelta, copy=True, ) ).__finalize__(self) From 356cb2e76ebeb70b50b6f197fa3996ae924d944e Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 15 Nov 2022 23:29:31 +0530 Subject: [PATCH 12/12] Update generic.py --- pandas/core/generic.py | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f8d61cd1e654b..5174f25e0da06 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4,6 +4,7 @@ import collections import datetime as dt import gc +import json import operator import pickle import re @@ -31,7 +32,6 @@ from pandas._config import config from pandas._libs import lib -import json from pandas._libs.tslibs import ( Period, Tick, @@ -130,7 +130,6 @@ notna, ) -from pandas.core import common # noqa: PDF018 from pandas.core import ( algorithms as algos, arraylike, @@ -139,17 +138,10 @@ nanops, sample, ) +from pandas.core import common # noqa: PDF018 from pandas.core.array_algos.replace import should_use_regex from pandas.core.arrays import ExtensionArray from pandas.core.base import PandasObject -from pandas.core.common import ( # noqa: PDF018 - apply_if_callable, - count_not_none, - get_rename_function, - index_labels_to_array, - maybe_make_list, - pipe, -) from pandas.core.construction import extract_array from pandas.core.describe import describe_ndframe from pandas.core.flags import Flags @@ -1017,7 +1009,7 @@ def _rename( continue ax = self._get_axis(axis_no) - f = get_rename_function(replacements) + f = common.get_rename_function(replacements) if level is not None: level = ax._get_level_number(level) @@ -1248,7 +1240,7 @@ class name if non_mapper: newnames = v else: - f = get_rename_function(v) + f = common.get_rename_function(v) curnames = self._get_axis(axis).names newnames = [f(name) for name in curnames] result._set_axis_name(newnames, axis=axis, inplace=True) @@ -1834,7 +1826,7 @@ def _drop_labels_or_levels(self, keys, axis: AxisInt = 0): axis = self._get_axis_number(axis) # Validate keys - keys = maybe_make_list(keys) + keys = common.maybe_make_list(keys) invalid_keys = [ k for k in keys if not self._is_label_or_level_reference(k, axis=axis) ] @@ -4453,7 +4445,7 @@ def _drop_axis( # Case for non-unique axis else: is_tuple_labels = is_nested_list_like(labels) or isinstance(labels, tuple) - labels = ensure_object(index_labels_to_array(labels)) + labels = ensure_object(common.index_labels_to_array(labels)) if level is not None: if not isinstance(axis, MultiIndex): raise AssertionError("axis must be a MultiIndex") @@ -5244,7 +5236,7 @@ def _reindex_axes( def _needs_reindex_multi(self, axes, method, level) -> bool_t: """Check if we do need a multi reindex.""" return ( - (count_not_none(*axes.values()) == self._AXIS_LEN) + (common.count_not_none(*axes.values()) == self._AXIS_LEN) and method is None and level is None and not self._is_mixed_type @@ -5367,7 +5359,7 @@ def filter( one two three rabbit 4 5 6 """ - nkw = count_not_none(items, like, regex) + nkw = common.count_not_none(items, like, regex) if nkw > 1: raise TypeError( "Keyword arguments `items`, `like`, or `regex` " @@ -5692,7 +5684,7 @@ def sample( obj_len = self.shape[axis] # Process random_state argument - rs = random_state(random_state) + rs = common.random_state(random_state) size = sample.process_sampling_size(n, frac, replace) if size is None: @@ -5768,7 +5760,7 @@ def pipe( ... .pipe((func, 'arg2'), arg1=a, arg3=c) ... ) # doctest: +SKIP """ - return pipe(self, func, *args, **kwargs) + return common.pipe(self, func, *args, **kwargs) # ---------------------------------------------------------------------- # Attribute access @@ -9453,7 +9445,7 @@ def _where( axis = self._get_axis_number(axis) # align the cond to same shape as myself - cond = apply_if_callable(cond, self) + cond = common.apply_if_callable(cond, self) if isinstance(cond, NDFrame): cond, _ = cond.align(self, join="right", broadcast_axis=1, copy=False) else: @@ -9755,7 +9747,7 @@ def where( 3 True True 4 True True """ - other = apply_if_callable(other, self) + other = common.apply_if_callable(other, self) return self._where(cond, other, inplace, axis, level) @overload @@ -9813,7 +9805,7 @@ def mask( ) -> NDFrameT | None: inplace = validate_bool_kwarg(inplace, "inplace") - cond = apply_if_callable(cond, self) + cond = common.apply_if_callable(cond, self) # see gh-21891 if not hasattr(cond, "__invert__"):