Skip to content

DEPR: Raise FutureWarning when creating empty series without dtype #42587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +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`)

.. ---------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/methods/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/methods/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
16 changes: 8 additions & 8 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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())

Expand All @@ -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)
Expand Down Expand Up @@ -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"]

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down