From 30c1cac454182c746d0310db52bb3aec2dc1ffd5 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 24 Dec 2020 12:14:30 +0000 Subject: [PATCH 1/4] Revert "DEPR: is_all_dates (#36697)" This reverts commit 90a61350b1be7a200238212bd8d118a25a4d3d95. --- doc/source/whatsnew/v1.2.0.rst | 2 -- pandas/core/generic.py | 8 +---- pandas/core/indexes/base.py | 15 +------- pandas/core/indexes/datetimelike.py | 2 +- pandas/core/indexes/interval.py | 2 +- pandas/core/indexes/multi.py | 2 +- pandas/core/indexes/numeric.py | 2 +- pandas/core/missing.py | 2 +- pandas/core/series.py | 9 +---- pandas/plotting/_matplotlib/core.py | 2 +- .../tests/indexes/interval/test_interval.py | 2 +- .../tests/indexes/multi/test_equivalence.py | 2 +- pandas/tests/indexes/test_base.py | 3 +- pandas/tests/indexing/test_indexing.py | 8 ++--- pandas/tests/io/pytables/test_store.py | 14 +++----- pandas/tests/series/test_constructors.py | 8 ++--- pandas/tests/series/test_repr.py | 4 +-- .../moments/test_moments_rolling_apply.py | 34 ++++++++----------- 18 files changed, 39 insertions(+), 82 deletions(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 6dc0d0cfaf80b..3d90ac0c2f93b 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -524,8 +524,6 @@ Deprecations - Deprecated indexing :class:`DataFrame` rows with a single datetime-like string as ``df[string]`` (given the ambiguity whether it is indexing the rows or selecting a column), use ``df.loc[string]`` instead (:issue:`36179`) -- Deprecated casting an object-dtype index of ``datetime`` objects to :class:`.DatetimeIndex` in the :class:`Series` constructor (:issue:`23598`) -- Deprecated :meth:`Index.is_all_dates` (:issue:`27744`) - The default value of ``regex`` for :meth:`Series.str.replace` will change from ``True`` to ``False`` in a future release. In addition, single character regular expressions will *not* be treated as literal strings when ``regex=True`` is set. (:issue:`24804`) - Deprecated automatic alignment on comparison operations between :class:`DataFrame` and :class:`Series`, do ``frame, ser = frame.align(ser, axis=1, copy=False)`` before e.g. ``frame == ser`` (:issue:`28759`) - :meth:`Rolling.count` with ``min_periods=None`` will default to the size of the window in a future version (:issue:`31302`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0985be5193200..87d74c0f4eaaf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9466,13 +9466,7 @@ def truncate( # if we have a date index, convert to dates, otherwise # treat like a slice - if ax._is_all_dates: - if is_object_dtype(ax.dtype): - warnings.warn( - "Treating object-dtype Index of date objects as DatetimeIndex " - "is deprecated, will be removed in a future version.", - FutureWarning, - ) + if ax.is_all_dates: from pandas.core.tools.datetimes import to_datetime before = to_datetime(before) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 8d48a6277d412..8ab177ec4a810 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2139,25 +2139,12 @@ def inferred_type(self) -> str_t: return lib.infer_dtype(self._values, skipna=False) @cache_readonly - def _is_all_dates(self) -> bool: + def is_all_dates(self) -> bool: """ Whether or not the index values only consist of dates. """ return is_datetime_array(ensure_object(self._values)) - @cache_readonly - def is_all_dates(self): - """ - Whether or not the index values only consist of dates. - """ - warnings.warn( - "Index.is_all_dates is deprecated, will be removed in a future version. " - "check index.inferred_type instead", - FutureWarning, - stacklevel=2, - ) - return self._is_all_dates - # -------------------------------------------------------------------- # Pickle Methods diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 94c055e264e71..0814f5d75fe64 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -124,7 +124,7 @@ def _simple_new( return result @property - def _is_all_dates(self) -> bool: + def is_all_dates(self) -> bool: return True # ------------------------------------------------------------------------ diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 1b3c4cfcccd2b..34eba4a9d14f6 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1021,7 +1021,7 @@ def func(self, other, sort=sort): # -------------------------------------------------------------------- @property - def _is_all_dates(self) -> bool: + def is_all_dates(self) -> bool: """ This is False even when left/right contain datetime-like objects, as the check is done on the Interval itself diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index c7be66b596246..879660645301d 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1805,7 +1805,7 @@ def to_flat_index(self): return Index(self._values, tupleize_cols=False) @property - def _is_all_dates(self) -> bool: + def is_all_dates(self) -> bool: return False def is_lexsorted(self) -> bool: diff --git a/pandas/core/indexes/numeric.py b/pandas/core/indexes/numeric.py index 91d27d9922aa5..94e9e58115070 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -176,7 +176,7 @@ def _assert_safe_casting(cls, data, subarr): pass @property - def _is_all_dates(self) -> bool: + def is_all_dates(self) -> bool: """ Checks that all the labels are datetime objects. """ diff --git a/pandas/core/missing.py b/pandas/core/missing.py index 1120416eebeb9..742cbd8b32146 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -313,7 +313,7 @@ def _interpolate_scipy_wrapper( "piecewise_polynomial": _from_derivatives, } - if getattr(x, "_is_all_dates", False): + if getattr(x, "is_all_dates", False): # GH 5975, scipy.interp1d can't handle datetime64s x, new_x = x._values.astype("i8"), new_x.astype("i8") diff --git a/pandas/core/series.py b/pandas/core/series.py index af8acc0a36e13..cab362490c2d5 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -423,7 +423,7 @@ def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None: if not fastpath: labels = ensure_index(labels) - if labels._is_all_dates: + if labels.is_all_dates: deep_labels = labels if isinstance(labels, CategoricalIndex): deep_labels = labels.categories @@ -436,13 +436,6 @@ def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None: # need to set here because we changed the index if fastpath: self._mgr.set_axis(axis, labels) - warnings.warn( - "Automatically casting object-dtype Index of datetimes to " - "DatetimeIndex is deprecated and will be removed in a " - "future version. Explicitly cast to DatetimeIndex instead.", - FutureWarning, - stacklevel=3, - ) except (tslibs.OutOfBoundsDatetime, ValueError): # labels may exceeds datetime bounds, # or not be a DatetimeIndex diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 3cf72edcc505e..b7eb6669e12e8 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1269,7 +1269,7 @@ def get_label(i): # would be too close together. condition = ( not self._use_dynamic_x() - and (data.index._is_all_dates and self.use_index) + and (data.index.is_all_dates and self.use_index) and (not self.subplots or (self.subplots and self.sharex)) ) diff --git a/pandas/tests/indexes/interval/test_interval.py b/pandas/tests/indexes/interval/test_interval.py index b8734ce8950f2..609959a7ef3a1 100644 --- a/pandas/tests/indexes/interval/test_interval.py +++ b/pandas/tests/indexes/interval/test_interval.py @@ -876,7 +876,7 @@ def test_is_all_dates(self): Timestamp("2017-01-01 00:00:00"), Timestamp("2018-01-01 00:00:00") ) year_2017_index = IntervalIndex([year_2017]) - assert not year_2017_index._is_all_dates + assert not year_2017_index.is_all_dates @pytest.mark.parametrize("key", [[5], (2, 3)]) def test_get_value_non_scalar_errors(self, key): diff --git a/pandas/tests/indexes/multi/test_equivalence.py b/pandas/tests/indexes/multi/test_equivalence.py index c44f7622c04dd..ba4b94e531697 100644 --- a/pandas/tests/indexes/multi/test_equivalence.py +++ b/pandas/tests/indexes/multi/test_equivalence.py @@ -260,7 +260,7 @@ def test_is_(): def test_is_all_dates(idx): - assert not idx._is_all_dates + assert not idx.is_all_dates def test_is_numeric(idx): diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index e5bb78604207f..3991b9f37137a 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1033,8 +1033,7 @@ def test_is_object(self, index, expected): indirect=["index"], ) def test_is_all_dates(self, index, expected): - with tm.assert_produces_warning(FutureWarning): - assert index.is_all_dates is expected + assert index.is_all_dates is expected def test_summary(self, index): self._check_method_works(Index._summary, index) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 05d9d1a9bd74f..e730fc0a3542d 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -530,17 +530,15 @@ def test_string_slice(self): # string indexing against datetimelike with object # dtype should properly raises KeyError df = DataFrame([1], Index([pd.Timestamp("2011-01-01")], dtype=object)) - assert df.index._is_all_dates + assert df.index.is_all_dates with pytest.raises(KeyError, match="'2011'"): df["2011"] with pytest.raises(KeyError, match="'2011'"): - with tm.assert_produces_warning(FutureWarning): - # This does an is_all_dates check - df.loc["2011", 0] + df.loc["2011", 0] df = DataFrame() - assert not df.index._is_all_dates + assert not df.index.is_all_dates with pytest.raises(KeyError, match="'2011'"): df["2011"] diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 274efda55414c..3f4c21389daed 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -2441,17 +2441,13 @@ def test_series(self, setup_path): ts = tm.makeTimeSeries() self._check_roundtrip(ts, tm.assert_series_equal, path=setup_path) - with tm.assert_produces_warning(FutureWarning): - # auto-casting object->DatetimeIndex deprecated - ts2 = Series(ts.index, Index(ts.index, dtype=object)) + ts2 = Series(ts.index, Index(ts.index, dtype=object)) self._check_roundtrip(ts2, tm.assert_series_equal, path=setup_path) - with tm.assert_produces_warning(FutureWarning): - # auto-casting object->DatetimeIndex deprecated - ts3 = Series( - ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object) - ) - self._check_roundtrip(ts3, tm.assert_series_equal, path=setup_path) + ts3 = Series(ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object)) + self._check_roundtrip( + ts3, tm.assert_series_equal, path=setup_path, check_index_type=False + ) def test_float_index(self, setup_path): diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index eabd6a1eb0743..0f9a1a673961c 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -104,11 +104,11 @@ def test_scalar_extension_dtype(self, ea_scalar_and_dtype): def test_constructor(self, datetime_series): with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): empty_series = Series() - assert datetime_series.index._is_all_dates + assert datetime_series.index.is_all_dates # Pass in Series derived = Series(datetime_series) - assert derived.index._is_all_dates + assert derived.index.is_all_dates assert tm.equalContents(derived.index, datetime_series.index) # Ensure new index is not created @@ -119,9 +119,9 @@ def test_constructor(self, datetime_series): assert mixed.dtype == np.object_ assert mixed[1] is np.NaN - assert not empty_series.index._is_all_dates + assert not empty_series.index.is_all_dates with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): - assert not Series().index._is_all_dates + assert not Series().index.is_all_dates # exception raised is of type ValueError GH35744 with pytest.raises(ValueError, match="Data must be 1-dimensional"): diff --git a/pandas/tests/series/test_repr.py b/pandas/tests/series/test_repr.py index 75e7f8a17eda3..836135c3d6310 100644 --- a/pandas/tests/series/test_repr.py +++ b/pandas/tests/series/test_repr.py @@ -184,9 +184,7 @@ def test_timeseries_repr_object_dtype(self): index = Index( [datetime(2000, 1, 1) + timedelta(i) for i in range(1000)], dtype=object ) - with tm.assert_produces_warning(FutureWarning): - # Index.is_all_dates deprecated - ts = Series(np.random.randn(len(index)), index) + ts = Series(np.random.randn(len(index)), index) repr(ts) ts = tm.makeTimeSeries(1000) diff --git a/pandas/tests/window/moments/test_moments_rolling_apply.py b/pandas/tests/window/moments/test_moments_rolling_apply.py index e9e672e1d3dae..e48d88b365d8d 100644 --- a/pandas/tests/window/moments/test_moments_rolling_apply.py +++ b/pandas/tests/window/moments/test_moments_rolling_apply.py @@ -122,16 +122,13 @@ def test_center_reindex_series(raw, series): s = [f"x{x:d}" for x in range(12)] minp = 10 - warn = None if raw else FutureWarning - with tm.assert_produces_warning(warn, check_stacklevel=False): - # GH#36697 is_all_dates deprecated - series_xp = ( - series.reindex(list(series.index) + s) - .rolling(window=25, min_periods=minp) - .apply(f, raw=raw) - .shift(-12) - .reindex(series.index) - ) + series_xp = ( + series.reindex(list(series.index) + s) + .rolling(window=25, min_periods=minp) + .apply(f, raw=raw) + .shift(-12) + .reindex(series.index) + ) series_rs = series.rolling(window=25, min_periods=minp, center=True).apply( f, raw=raw ) @@ -143,15 +140,12 @@ def test_center_reindex_frame(raw, frame): s = [f"x{x:d}" for x in range(12)] minp = 10 - warn = None if raw else FutureWarning - with tm.assert_produces_warning(warn, check_stacklevel=False): - # GH#36697 is_all_dates deprecated - frame_xp = ( - frame.reindex(list(frame.index) + s) - .rolling(window=25, min_periods=minp) - .apply(f, raw=raw) - .shift(-12) - .reindex(frame.index) - ) + frame_xp = ( + frame.reindex(list(frame.index) + s) + .rolling(window=25, min_periods=minp) + .apply(f, raw=raw) + .shift(-12) + .reindex(frame.index) + ) frame_rs = frame.rolling(window=25, min_periods=minp, center=True).apply(f, raw=raw) tm.assert_frame_equal(frame_xp, frame_rs) From 20eaa266f220c97e04712a01c93c071cdf736471 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 24 Dec 2020 12:40:14 +0000 Subject: [PATCH 2/4] revert Deprecated casting an object-dtype index of ``datetime`` objects to :class:`.DatetimeIndex` in the :class:`Series` constructor (:issue:`23598`) only --- doc/source/whatsnew/v1.2.0.rst | 1 + pandas/core/generic.py | 2 +- pandas/core/indexes/base.py | 15 ++++++++++++++- pandas/core/indexes/datetimelike.py | 2 +- pandas/core/indexes/interval.py | 2 +- pandas/core/indexes/multi.py | 2 +- pandas/core/indexes/numeric.py | 2 +- pandas/core/missing.py | 2 +- pandas/core/series.py | 2 +- pandas/plotting/_matplotlib/core.py | 2 +- pandas/tests/indexes/interval/test_interval.py | 2 +- pandas/tests/indexes/multi/test_equivalence.py | 2 +- pandas/tests/indexes/test_base.py | 3 ++- pandas/tests/indexing/test_indexing.py | 4 ++-- pandas/tests/series/test_constructors.py | 8 ++++---- 15 files changed, 33 insertions(+), 18 deletions(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 3d90ac0c2f93b..d947b6a495a75 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -524,6 +524,7 @@ Deprecations - Deprecated indexing :class:`DataFrame` rows with a single datetime-like string as ``df[string]`` (given the ambiguity whether it is indexing the rows or selecting a column), use ``df.loc[string]`` instead (:issue:`36179`) +- Deprecated :meth:`Index.is_all_dates` (:issue:`27744`) - The default value of ``regex`` for :meth:`Series.str.replace` will change from ``True`` to ``False`` in a future release. In addition, single character regular expressions will *not* be treated as literal strings when ``regex=True`` is set. (:issue:`24804`) - Deprecated automatic alignment on comparison operations between :class:`DataFrame` and :class:`Series`, do ``frame, ser = frame.align(ser, axis=1, copy=False)`` before e.g. ``frame == ser`` (:issue:`28759`) - :meth:`Rolling.count` with ``min_periods=None`` will default to the size of the window in a future version (:issue:`31302`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 87d74c0f4eaaf..2f0f40fb9ed0a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9466,7 +9466,7 @@ def truncate( # if we have a date index, convert to dates, otherwise # treat like a slice - if ax.is_all_dates: + if ax._is_all_dates: from pandas.core.tools.datetimes import to_datetime before = to_datetime(before) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 8ab177ec4a810..8d48a6277d412 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2139,12 +2139,25 @@ def inferred_type(self) -> str_t: return lib.infer_dtype(self._values, skipna=False) @cache_readonly - def is_all_dates(self) -> bool: + def _is_all_dates(self) -> bool: """ Whether or not the index values only consist of dates. """ return is_datetime_array(ensure_object(self._values)) + @cache_readonly + def is_all_dates(self): + """ + Whether or not the index values only consist of dates. + """ + warnings.warn( + "Index.is_all_dates is deprecated, will be removed in a future version. " + "check index.inferred_type instead", + FutureWarning, + stacklevel=2, + ) + return self._is_all_dates + # -------------------------------------------------------------------- # Pickle Methods diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 0814f5d75fe64..94c055e264e71 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -124,7 +124,7 @@ def _simple_new( return result @property - def is_all_dates(self) -> bool: + def _is_all_dates(self) -> bool: return True # ------------------------------------------------------------------------ diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 34eba4a9d14f6..1b3c4cfcccd2b 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1021,7 +1021,7 @@ def func(self, other, sort=sort): # -------------------------------------------------------------------- @property - def is_all_dates(self) -> bool: + def _is_all_dates(self) -> bool: """ This is False even when left/right contain datetime-like objects, as the check is done on the Interval itself diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 879660645301d..c7be66b596246 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1805,7 +1805,7 @@ def to_flat_index(self): return Index(self._values, tupleize_cols=False) @property - def is_all_dates(self) -> bool: + def _is_all_dates(self) -> bool: return False def is_lexsorted(self) -> bool: diff --git a/pandas/core/indexes/numeric.py b/pandas/core/indexes/numeric.py index 94e9e58115070..91d27d9922aa5 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -176,7 +176,7 @@ def _assert_safe_casting(cls, data, subarr): pass @property - def is_all_dates(self) -> bool: + def _is_all_dates(self) -> bool: """ Checks that all the labels are datetime objects. """ diff --git a/pandas/core/missing.py b/pandas/core/missing.py index 742cbd8b32146..1120416eebeb9 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -313,7 +313,7 @@ def _interpolate_scipy_wrapper( "piecewise_polynomial": _from_derivatives, } - if getattr(x, "is_all_dates", False): + if getattr(x, "_is_all_dates", False): # GH 5975, scipy.interp1d can't handle datetime64s x, new_x = x._values.astype("i8"), new_x.astype("i8") diff --git a/pandas/core/series.py b/pandas/core/series.py index cab362490c2d5..d4ae5c2245b5b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -423,7 +423,7 @@ def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None: if not fastpath: labels = ensure_index(labels) - if labels.is_all_dates: + if labels._is_all_dates: deep_labels = labels if isinstance(labels, CategoricalIndex): deep_labels = labels.categories diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index b7eb6669e12e8..3cf72edcc505e 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1269,7 +1269,7 @@ def get_label(i): # would be too close together. condition = ( not self._use_dynamic_x() - and (data.index.is_all_dates and self.use_index) + and (data.index._is_all_dates and self.use_index) and (not self.subplots or (self.subplots and self.sharex)) ) diff --git a/pandas/tests/indexes/interval/test_interval.py b/pandas/tests/indexes/interval/test_interval.py index 609959a7ef3a1..b8734ce8950f2 100644 --- a/pandas/tests/indexes/interval/test_interval.py +++ b/pandas/tests/indexes/interval/test_interval.py @@ -876,7 +876,7 @@ def test_is_all_dates(self): Timestamp("2017-01-01 00:00:00"), Timestamp("2018-01-01 00:00:00") ) year_2017_index = IntervalIndex([year_2017]) - assert not year_2017_index.is_all_dates + assert not year_2017_index._is_all_dates @pytest.mark.parametrize("key", [[5], (2, 3)]) def test_get_value_non_scalar_errors(self, key): diff --git a/pandas/tests/indexes/multi/test_equivalence.py b/pandas/tests/indexes/multi/test_equivalence.py index ba4b94e531697..c44f7622c04dd 100644 --- a/pandas/tests/indexes/multi/test_equivalence.py +++ b/pandas/tests/indexes/multi/test_equivalence.py @@ -260,7 +260,7 @@ def test_is_(): def test_is_all_dates(idx): - assert not idx.is_all_dates + assert not idx._is_all_dates def test_is_numeric(idx): diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 3991b9f37137a..e5bb78604207f 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1033,7 +1033,8 @@ def test_is_object(self, index, expected): indirect=["index"], ) def test_is_all_dates(self, index, expected): - assert index.is_all_dates is expected + with tm.assert_produces_warning(FutureWarning): + assert index.is_all_dates is expected def test_summary(self, index): self._check_method_works(Index._summary, index) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index e730fc0a3542d..b39bf980642b1 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -530,7 +530,7 @@ def test_string_slice(self): # string indexing against datetimelike with object # dtype should properly raises KeyError df = DataFrame([1], Index([pd.Timestamp("2011-01-01")], dtype=object)) - assert df.index.is_all_dates + assert df.index._is_all_dates with pytest.raises(KeyError, match="'2011'"): df["2011"] @@ -538,7 +538,7 @@ def test_string_slice(self): df.loc["2011", 0] df = DataFrame() - assert not df.index.is_all_dates + assert not df.index._is_all_dates with pytest.raises(KeyError, match="'2011'"): df["2011"] diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 0f9a1a673961c..eabd6a1eb0743 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -104,11 +104,11 @@ def test_scalar_extension_dtype(self, ea_scalar_and_dtype): def test_constructor(self, datetime_series): with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): empty_series = Series() - assert datetime_series.index.is_all_dates + assert datetime_series.index._is_all_dates # Pass in Series derived = Series(datetime_series) - assert derived.index.is_all_dates + assert derived.index._is_all_dates assert tm.equalContents(derived.index, datetime_series.index) # Ensure new index is not created @@ -119,9 +119,9 @@ def test_constructor(self, datetime_series): assert mixed.dtype == np.object_ assert mixed[1] is np.NaN - assert not empty_series.index.is_all_dates + assert not empty_series.index._is_all_dates with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): - assert not Series().index.is_all_dates + assert not Series().index._is_all_dates # exception raised is of type ValueError GH35744 with pytest.raises(ValueError, match="Data must be 1-dimensional"): From 463a4db6392810b756bea64668d627a85a73c932 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 24 Dec 2020 13:02:09 +0000 Subject: [PATCH 3/4] Revert "BUG: record warnings related to DatetimeIndex (#37193)" This reverts commit 23c41bd1fa9c27cac08416d2b49cd4d34da77172. --- pandas/tests/plotting/test_datetimelike.py | 26 +++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 397a064f6adad..66a4f9598c49b 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -277,16 +277,9 @@ def test_irreg_hf(self): _, ax = self.plt.subplots() df2 = df.copy() df2.index = df.index.astype(object) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # This warning will be emitted - # pandas/core/frame.py:3216: - # FutureWarning: Automatically casting object-dtype Index of datetimes - # to DatetimeIndex is deprecated and will be removed in a future version. - # Explicitly cast to DatetimeIndex instead. - # return klass(values, index=self.index, name=name, fastpath=True) - df2.plot(ax=ax) - diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff() - assert (np.fabs(diffs[1:] - sec) < 1e-8).all() + df2.plot(ax=ax) + diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff() + assert (np.fabs(diffs[1:] - sec) < 1e-8).all() def test_irregular_datetime64_repr_bug(self): ser = tm.makeTimeSeries() @@ -997,16 +990,9 @@ def test_irreg_dtypes(self): # np.datetime64 idx = date_range("1/1/2000", periods=10) idx = idx[[0, 2, 5, 9]].astype(object) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # This warning will be emitted - # pandas/core/frame.py:3216: - # FutureWarning: Automatically casting object-dtype Index of datetimes - # to DatetimeIndex is deprecated and will be removed in a future version. - # Explicitly cast to DatetimeIndex instead. - # return klass(values, index=self.index, name=name, fastpath=True) - df = DataFrame(np.random.randn(len(idx), 3), idx) - _, ax = self.plt.subplots() - _check_plot_works(df.plot, ax=ax) + df = DataFrame(np.random.randn(len(idx), 3), idx) + _, ax = self.plt.subplots() + _check_plot_works(df.plot, ax=ax) def test_time(self): t = datetime(1, 1, 1, 3, 30, 0) From 6df30687afad2fad3d9ba902c6aed2b010bb59e3 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 24 Dec 2020 13:37:01 +0000 Subject: [PATCH 4/4] remove assert_produces_warning added in TST/REF: collect tests by method, some misplaced #37354 --- pandas/tests/series/test_constructors.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index eabd6a1eb0743..ca7a171947ca0 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1623,8 +1623,7 @@ def test_constructor_infer_index_tz(self): class TestSeriesConstructorIndexCoercion: def test_series_constructor_datetimelike_index_coercion(self): idx = tm.makeDateIndex(10000) - with tm.assert_produces_warning(FutureWarning): - ser = Series(np.random.randn(len(idx)), idx.astype(object)) + ser = Series(np.random.randn(len(idx)), idx.astype(object)) with tm.assert_produces_warning(FutureWarning): assert ser.index.is_all_dates assert isinstance(ser.index, DatetimeIndex)