From 8ba1bfdf80cd59c7a851a002c883836ec4f240f1 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 25 Dec 2019 16:57:32 -0800 Subject: [PATCH 1/7] GH ref for 30460 --- doc/source/whatsnew/v1.0.0.rst | 1 + pandas/core/generic.py | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 9694289fc22d5..ed1322540b3f9 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -716,6 +716,7 @@ Datetimelike - Bug in :meth:`Series.item` with ``datetime64`` or ``timedelta64`` dtype, :meth:`DatetimeIndex.item`, and :meth:`TimedeltaIndex.item` returning an integer instead of a :class:`Timestamp` or :class:`Timedelta` (:issue:`30175`) - Bug in :class:`DatetimeIndex` addition when adding a non-optimized :class:`DateOffset` incorrectly dropping timezone information (:issue:`30336`) - Bug in :meth:`DataFrame.append` would remove the timezone-awareness of new data (:issue:`30238`) +- Bug in :meth:`Series.cummin` and :meth:`Series.cummax` with timezone-aware dtype incorrectly dropping its timezone (:issue:`15553`) Timedelta ^^^^^^^^^ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f846d5883a8b5..304951ea8562d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11106,6 +11106,7 @@ def cum_func(self, axis=None, skipna=True, *args, **kwargs): d["copy"] = False if issubclass(y.dtype.type, (np.datetime64, np.timedelta64)): + # GH#30460, GH#29058 # numpy 1.18 started sorting NaTs at the end instead of beginning, # so we need to work around to maintain backwards-consistency. orig_dtype = y.dtype From 14840657bb32ea3e7c142559fdc8ca24ac89b2ae Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 27 Dec 2019 13:21:51 -0800 Subject: [PATCH 2/7] whatsnew for 29853 --- doc/source/whatsnew/v1.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 98aef3b376c77..b6e68516a1310 100755 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -659,6 +659,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. Performance improvements ~~~~~~~~~~~~~~~~~~~~~~~~ +- Performance improvement in arithmetic and comparison operations between a :class:`DataFrame` and scalar (:issue:`29853`) - Performance improvement in indexing with a non-unique :class:`IntervalIndex` (:issue:`27489`) - Performance improvement in :attr:`MultiIndex.is_monotonic` (:issue:`27495`) - Performance improvement in :func:`cut` when ``bins`` is an :class:`IntervalIndex` (:issue:`27668`) From 148dd14ac282cd8c10f890931bb7532cac758528 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 27 Dec 2019 14:59:31 -0800 Subject: [PATCH 3/7] remove validate_cmpress --- pandas/compat/numpy/function.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pandas/compat/numpy/function.py b/pandas/compat/numpy/function.py index fffe09a74571e..7158f251ad805 100644 --- a/pandas/compat/numpy/function.py +++ b/pandas/compat/numpy/function.py @@ -169,13 +169,6 @@ def validate_clip_with_axis(axis, args, kwargs): return axis -COMPRESS_DEFAULTS: "OrderedDict[str, Any]" = OrderedDict() -COMPRESS_DEFAULTS["axis"] = None -COMPRESS_DEFAULTS["out"] = None -validate_compress = CompatValidator( - COMPRESS_DEFAULTS, fname="compress", method="both", max_fname_arg_count=1 -) - CUM_FUNC_DEFAULTS: "OrderedDict[str, Any]" = OrderedDict() CUM_FUNC_DEFAULTS["dtype"] = None CUM_FUNC_DEFAULTS["out"] = None From 5814a4c96b93ba7bb0bf44452244b597133e72b6 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 30 Dec 2019 09:50:43 -0800 Subject: [PATCH 4/7] remove defunct comment --- pandas/tests/indexes/datetimes/test_constructors.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 58ab44fba08cf..2f1fa3ce627e6 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -711,7 +711,6 @@ def test_constructor_timestamp_near_dst(self): expected = DatetimeIndex([ts[0].to_pydatetime(), ts[1].to_pydatetime()]) tm.assert_index_equal(result, expected) - # TODO(GH-24559): Remove the xfail for the tz-aware case. @pytest.mark.parametrize("klass", [Index, DatetimeIndex]) @pytest.mark.parametrize("box", [np.array, partial(np.array, dtype=object), list]) @pytest.mark.parametrize( From 5eb27726b153847a1fc83ede11d467ef1c8639ee Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 30 Dec 2019 13:28:05 -0800 Subject: [PATCH 5/7] annotate getattr --- pandas/__init__.py | 4 ++-- pandas/_config/config.py | 2 +- pandas/core/groupby/groupby.py | 4 ++-- pandas/core/resample.py | 2 +- pandas/core/window/rolling.py | 2 +- pandas/util/_depr_module.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 99495d4b7dcb6..ef14e9cbda2ea 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -192,7 +192,7 @@ # TODO: remove Panel compat in 1.0 if pandas.compat.PY37: - def __getattr__(name): + def __getattr__(name: str): import warnings if name == "Panel": @@ -256,7 +256,7 @@ def __init__(self): self.np = np self.warnings = warnings - def __getattr__(self, item): + def __getattr__(self, item: str): self.warnings.warn( "The pandas.np module is deprecated " "and will be removed from pandas in a future version. " diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 6844df495547a..0a3009f74492f 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -197,7 +197,7 @@ def __setattr__(self, key, val): else: raise OptionError("You can only set the value of existing options") - def __getattr__(self, key): + def __getattr__(self, key: str): prefix = object.__getattribute__(self, "prefix") if prefix: prefix += "." diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 227547daf3668..f08ed3435af9b 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -325,7 +325,7 @@ def f(self): f.__name__ = "plot" return self._groupby.apply(f) - def __getattr__(self, name): + def __getattr__(self, name: str): def attr(*args, **kwargs): def f(self): return getattr(self.plot, name)(*args, **kwargs) @@ -570,7 +570,7 @@ def _set_result_index_ordered(self, result): def _dir_additions(self): return self.obj._dir_additions() | self._apply_whitelist - def __getattr__(self, attr): + def __getattr__(self, attr: str): if attr in self._internal_names_set: return object.__getattribute__(self, attr) if attr in self.obj: diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 9ae0aa930779b..6ddb656a484b6 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -96,7 +96,7 @@ def __str__(self) -> str: ) return f"{type(self).__name__} [{', '.join(attrs)}]" - def __getattr__(self, attr): + def __getattr__(self, attr: str): if attr in self._internal_names_set: return object.__getattribute__(self, attr) if attr in self._attributes: diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 5b0fbbb3518d2..176406f953f67 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -184,7 +184,7 @@ def _gotitem(self, key, ndim, subset=None): self._selection = key return self - def __getattr__(self, attr): + def __getattr__(self, attr: str): if attr in self._internal_names_set: return object.__getattribute__(self, attr) if attr in self.obj: diff --git a/pandas/util/_depr_module.py b/pandas/util/_depr_module.py index 5733663dd7ab3..5694ca24aab57 100644 --- a/pandas/util/_depr_module.py +++ b/pandas/util/_depr_module.py @@ -46,7 +46,7 @@ def __repr__(self) -> str: __str__ = __repr__ - def __getattr__(self, name): + def __getattr__(self, name: str): if name in self.self_dir: return object.__getattribute__(self, name) From b74b501f8bfe7dd4f4f21673eb800195a02a2984 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 30 Dec 2019 13:33:35 -0800 Subject: [PATCH 6/7] annotations --- pandas/core/resample.py | 8 ++++---- pandas/core/reshape/concat.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 6ddb656a484b6..931653b63af36 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -131,7 +131,7 @@ def ax(self): return self.groupby.ax @property - def _typ(self): + def _typ(self) -> str: """ Masquerade for compat as a Series or a DataFrame. """ @@ -140,7 +140,7 @@ def _typ(self): return "dataframe" @property - def _from_selection(self): + def _from_selection(self) -> bool: """ Is the resampling from a DataFrame column or MultiIndex level. """ @@ -316,7 +316,7 @@ def _downsample(self, f): def _upsample(self, f, limit=None, fill_value=None): raise AbstractMethodError(self) - def _gotitem(self, key, ndim, subset=None): + def _gotitem(self, key, ndim: int, subset=None): """ Sub-classes to define. Return a sliced object. @@ -1407,7 +1407,7 @@ def _get_resampler(self, obj, kind=None): f"but got an instance of '{type(ax).__name__}'" ) - def _get_grouper(self, obj, validate=True): + def _get_grouper(self, obj, validate: bool = True): # create the resampler and return our binner r = self._get_resampler(obj) r._set_binner() diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index cea70012b47ea..a3d9dbfba9e71 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -472,9 +472,9 @@ def _get_result_dim(self) -> int: else: return self.objs[0].ndim - def _get_new_axes(self): + def _get_new_axes(self) -> List[Index]: ndim = self._get_result_dim() - new_axes = [None] * ndim + new_axes: List = [None] * ndim for i in range(ndim): if i == self.axis: From e70b940a7d657171089822da02c1b826070b54d7 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 30 Dec 2019 15:26:45 -0800 Subject: [PATCH 7/7] revert bc mypy doesnt know about warnings.warn --- pandas/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index ef14e9cbda2ea..99495d4b7dcb6 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -192,7 +192,7 @@ # TODO: remove Panel compat in 1.0 if pandas.compat.PY37: - def __getattr__(name: str): + def __getattr__(name): import warnings if name == "Panel": @@ -256,7 +256,7 @@ def __init__(self): self.np = np self.warnings = warnings - def __getattr__(self, item: str): + def __getattr__(self, item): self.warnings.warn( "The pandas.np module is deprecated " "and will be removed from pandas in a future version. "