From 44e6cda010a281fd509df432c222214902af8725 Mon Sep 17 00:00:00 2001 From: Thomas Li Date: Sat, 17 Jul 2021 10:18:20 -0700 Subject: [PATCH 1/2] DEPR: Raise FutureWarning when creating empty series without dtype --- doc/source/whatsnew/v1.4.0.rst | 2 +- pandas/core/series.py | 4 ++-- pandas/tests/series/methods/test_astype.py | 2 +- pandas/tests/series/methods/test_replace.py | 2 +- pandas/tests/series/test_constructors.py | 16 ++++++++-------- pandas/tests/series/test_subclass.py | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 8608dffd58090..324dbeb562e90 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -155,7 +155,7 @@ Deprecations - Deprecated treating integer keys in :meth:`Series.__setitem__` as positional when the index is a :class:`Float64Index` not containing the key, a :class:`IntervalIndex` with no entries containing the key, or a :class:`MultiIndex` with leading :class:`Float64Index` level not containing the key (:issue:`33469`) - Deprecated treating ``numpy.datetime64`` objects as UTC times when passed to the :class:`Timestamp` constructor along with a timezone. In a future version, these will be treated as wall-times. To retain the old behavior, use ``Timestamp(dt64).tz_localize("UTC").tz_convert(tz)`` (:issue:`24559`) - Deprecated ignoring missing labels when indexing with a sequence of labels on a level of a MultiIndex (:issue:`42351`) - +- Creating an empty Series without a dtype will now raise a more visible ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`30017`) .. --------------------------------------------------------------------------- .. _whatsnew_140.performance: diff --git a/pandas/core/series.py b/pandas/core/series.py index e61ce8e74629b..feda7d83af997 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -354,10 +354,10 @@ def __init__( "The default dtype for empty Series will be 'object' instead " "of 'float64' in a future version. Specify a dtype explicitly " "to silence this warning.", - DeprecationWarning, + FutureWarning, stacklevel=2, ) - # uncomment the line below when removing the DeprecationWarning + # uncomment the line below when removing the FutureWarning # dtype = np.dtype(object) if index is not None: diff --git a/pandas/tests/series/methods/test_astype.py b/pandas/tests/series/methods/test_astype.py index 99a7ba910eb74..c1fedb14be949 100644 --- a/pandas/tests/series/methods/test_astype.py +++ b/pandas/tests/series/methods/test_astype.py @@ -92,7 +92,7 @@ def test_astype_empty_constructor_equality(self, dtype): "m", # Generic timestamps raise a ValueError. Already tested. ): init_empty = Series([], dtype=dtype) - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): as_type_empty = Series([]).astype(dtype) tm.assert_series_equal(init_empty, as_type_empty) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index c32d74c17a47e..ef4b6174909c5 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -266,7 +266,7 @@ def test_replace_with_empty_dictlike(self): s = pd.Series(list("abcd")) tm.assert_series_equal(s, s.replace({})) - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): empty_series = pd.Series([]) tm.assert_series_equal(s, s.replace(empty_series)) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 56af003c59bf5..8525edc8dee80 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -71,7 +71,7 @@ class TestSeriesConstructors: ) def test_empty_constructor(self, constructor, check_index_type): # TODO: share with frame test of the same name - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): expected = Series() result = constructor() @@ -116,7 +116,7 @@ def test_scalar_extension_dtype(self, ea_scalar_and_dtype): tm.assert_series_equal(ser, expected) def test_constructor(self, datetime_series): - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): empty_series = Series() assert datetime_series.index._is_all_dates @@ -134,7 +134,7 @@ def test_constructor(self, datetime_series): assert mixed[1] is np.NaN assert not empty_series.index._is_all_dates - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): assert not Series().index._is_all_dates # exception raised is of type ValueError GH35744 @@ -154,7 +154,7 @@ def test_constructor(self, datetime_series): @pytest.mark.parametrize("input_class", [list, dict, OrderedDict]) def test_constructor_empty(self, input_class): - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): empty = Series() empty2 = Series(input_class()) @@ -174,7 +174,7 @@ def test_constructor_empty(self, input_class): if input_class is not list: # With index: - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): empty = Series(index=range(10)) empty2 = Series(input_class(), index=range(10)) tm.assert_series_equal(empty, empty2) @@ -208,7 +208,7 @@ def test_constructor_dtype_only(self, dtype, index): assert len(result) == 0 def test_constructor_no_data_index_order(self): - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): result = Series(index=["b", "a", "c"]) assert result.index.tolist() == ["b", "a", "c"] @@ -674,7 +674,7 @@ def test_constructor_limit_copies(self, index): assert s._mgr.blocks[0].values is not index def test_constructor_pass_none(self): - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): s = Series(None, index=range(5)) assert s.dtype == np.float64 @@ -683,7 +683,7 @@ def test_constructor_pass_none(self): # GH 7431 # inference on the index - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): s = Series(index=np.array([None])) expected = Series(index=Index([None])) tm.assert_series_equal(s, expected) diff --git a/pandas/tests/series/test_subclass.py b/pandas/tests/series/test_subclass.py index da5faeab49a8d..c34dceab12749 100644 --- a/pandas/tests/series/test_subclass.py +++ b/pandas/tests/series/test_subclass.py @@ -35,7 +35,7 @@ def test_subclass_unstack(self): tm.assert_frame_equal(res, exp) def test_subclass_empty_repr(self): - with tm.assert_produces_warning(DeprecationWarning): + with tm.assert_produces_warning(FutureWarning): sub_series = tm.SubclassedSeries() assert "SubclassedSeries" in repr(sub_series) From a5aaad06ca4ad726700f10b004adec8fa22c1ea8 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sat, 17 Jul 2021 11:14:40 -0700 Subject: [PATCH 2/2] Add blank line to placate web and docs --- doc/source/whatsnew/v1.4.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 324dbeb562e90..e07f927fa4a48 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -156,6 +156,7 @@ Deprecations - Deprecated treating ``numpy.datetime64`` objects as UTC times when passed to the :class:`Timestamp` constructor along with a timezone. In a future version, these will be treated as wall-times. To retain the old behavior, use ``Timestamp(dt64).tz_localize("UTC").tz_convert(tz)`` (:issue:`24559`) - Deprecated ignoring missing labels when indexing with a sequence of labels on a level of a MultiIndex (:issue:`42351`) - Creating an empty Series without a dtype will now raise a more visible ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`30017`) + .. --------------------------------------------------------------------------- .. _whatsnew_140.performance: