Skip to content

Commit b5e2278

Browse files
authored
DEPR: Raise FutureWarning when creating empty series without dtype (#42587)
1 parent 41c90cf commit b5e2278

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Deprecations
155155
- 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`)
156156
- 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`)
157157
- Deprecated ignoring missing labels when indexing with a sequence of labels on a level of a MultiIndex (:issue:`42351`)
158+
- Creating an empty Series without a dtype will now raise a more visible ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`30017`)
158159

159160
.. ---------------------------------------------------------------------------
160161

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,10 @@ def __init__(
354354
"The default dtype for empty Series will be 'object' instead "
355355
"of 'float64' in a future version. Specify a dtype explicitly "
356356
"to silence this warning.",
357-
DeprecationWarning,
357+
FutureWarning,
358358
stacklevel=2,
359359
)
360-
# uncomment the line below when removing the DeprecationWarning
360+
# uncomment the line below when removing the FutureWarning
361361
# dtype = np.dtype(object)
362362

363363
if index is not None:

pandas/tests/series/methods/test_astype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_astype_empty_constructor_equality(self, dtype):
9292
"m", # Generic timestamps raise a ValueError. Already tested.
9393
):
9494
init_empty = Series([], dtype=dtype)
95-
with tm.assert_produces_warning(DeprecationWarning):
95+
with tm.assert_produces_warning(FutureWarning):
9696
as_type_empty = Series([]).astype(dtype)
9797
tm.assert_series_equal(init_empty, as_type_empty)
9898

pandas/tests/series/methods/test_replace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_replace_with_empty_dictlike(self):
266266
s = pd.Series(list("abcd"))
267267
tm.assert_series_equal(s, s.replace({}))
268268

269-
with tm.assert_produces_warning(DeprecationWarning):
269+
with tm.assert_produces_warning(FutureWarning):
270270
empty_series = pd.Series([])
271271
tm.assert_series_equal(s, s.replace(empty_series))
272272

pandas/tests/series/test_constructors.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TestSeriesConstructors:
7171
)
7272
def test_empty_constructor(self, constructor, check_index_type):
7373
# TODO: share with frame test of the same name
74-
with tm.assert_produces_warning(DeprecationWarning):
74+
with tm.assert_produces_warning(FutureWarning):
7575
expected = Series()
7676
result = constructor()
7777

@@ -116,7 +116,7 @@ def test_scalar_extension_dtype(self, ea_scalar_and_dtype):
116116
tm.assert_series_equal(ser, expected)
117117

118118
def test_constructor(self, datetime_series):
119-
with tm.assert_produces_warning(DeprecationWarning):
119+
with tm.assert_produces_warning(FutureWarning):
120120
empty_series = Series()
121121
assert datetime_series.index._is_all_dates
122122

@@ -134,7 +134,7 @@ def test_constructor(self, datetime_series):
134134
assert mixed[1] is np.NaN
135135

136136
assert not empty_series.index._is_all_dates
137-
with tm.assert_produces_warning(DeprecationWarning):
137+
with tm.assert_produces_warning(FutureWarning):
138138
assert not Series().index._is_all_dates
139139

140140
# exception raised is of type ValueError GH35744
@@ -154,7 +154,7 @@ def test_constructor(self, datetime_series):
154154

155155
@pytest.mark.parametrize("input_class", [list, dict, OrderedDict])
156156
def test_constructor_empty(self, input_class):
157-
with tm.assert_produces_warning(DeprecationWarning):
157+
with tm.assert_produces_warning(FutureWarning):
158158
empty = Series()
159159
empty2 = Series(input_class())
160160

@@ -174,7 +174,7 @@ def test_constructor_empty(self, input_class):
174174

175175
if input_class is not list:
176176
# With index:
177-
with tm.assert_produces_warning(DeprecationWarning):
177+
with tm.assert_produces_warning(FutureWarning):
178178
empty = Series(index=range(10))
179179
empty2 = Series(input_class(), index=range(10))
180180
tm.assert_series_equal(empty, empty2)
@@ -208,7 +208,7 @@ def test_constructor_dtype_only(self, dtype, index):
208208
assert len(result) == 0
209209

210210
def test_constructor_no_data_index_order(self):
211-
with tm.assert_produces_warning(DeprecationWarning):
211+
with tm.assert_produces_warning(FutureWarning):
212212
result = Series(index=["b", "a", "c"])
213213
assert result.index.tolist() == ["b", "a", "c"]
214214

@@ -674,7 +674,7 @@ def test_constructor_limit_copies(self, index):
674674
assert s._mgr.blocks[0].values is not index
675675

676676
def test_constructor_pass_none(self):
677-
with tm.assert_produces_warning(DeprecationWarning):
677+
with tm.assert_produces_warning(FutureWarning):
678678
s = Series(None, index=range(5))
679679
assert s.dtype == np.float64
680680

@@ -683,7 +683,7 @@ def test_constructor_pass_none(self):
683683

684684
# GH 7431
685685
# inference on the index
686-
with tm.assert_produces_warning(DeprecationWarning):
686+
with tm.assert_produces_warning(FutureWarning):
687687
s = Series(index=np.array([None]))
688688
expected = Series(index=Index([None]))
689689
tm.assert_series_equal(s, expected)

pandas/tests/series/test_subclass.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_subclass_unstack(self):
3535
tm.assert_frame_equal(res, exp)
3636

3737
def test_subclass_empty_repr(self):
38-
with tm.assert_produces_warning(DeprecationWarning):
38+
with tm.assert_produces_warning(FutureWarning):
3939
sub_series = tm.SubclassedSeries()
4040
assert "SubclassedSeries" in repr(sub_series)
4141

0 commit comments

Comments
 (0)