Skip to content

DEPR: Enforce deprecations #49589

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 3 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ Removal of prior version deprecations/changes
- Disallow passing abbreviations for ``orient`` in :meth:`DataFrame.to_dict` (:issue:`32516`)
- Removed ``get_offset`` in favor of :func:`to_offset` (:issue:`30340`)
- Removed the ``warn`` keyword in :func:`infer_freq` (:issue:`45947`)
- Removed the ``include_start`` and ``include_end`` arguments in :meth:`DataFrame.between_time` in favor of ``inclusive`` (:issue:`43248`)
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
- Removed the ``truediv`` keyword from :func:`eval` (:issue:`29812`)
- Removed the ``pandas.datetime`` submodule (:issue:`30489`)
Expand All @@ -457,6 +458,7 @@ Removal of prior version deprecations/changes
- Enforced disallowing :func:`merge` to produce duplicated columns through the ``suffixes`` keyword and already existing columns (:issue:`22818`)
- Enforced disallowing using :func:`merge` or :func:`join` on a different number of levels (:issue:`34862`)
- Enforced disallowing ``value_name`` argument in :func:`DataFrame.melt` to match an element in the :class:`DataFrame` columns (:issue:`35003`)
- Enforced disallowing passing ``showindex`` into ``**kwargs`` in :func:`DataFrame.to_markdown` and :func:`Series.to_markdown` in favor of ``index`` (:issue:`33091`)
- Removed setting Categorical._codes directly (:issue:`41429`)
- Removed setting Categorical.categories directly (:issue:`47834`)
- Removed argument ``inplace`` from :meth:`Categorical.add_categories`, :meth:`Categorical.remove_categories`, :meth:`Categorical.set_categories`, :meth:`Categorical.rename_categories`, :meth:`Categorical.reorder_categories`, :meth:`Categorical.set_ordered`, :meth:`Categorical.as_ordered`, :meth:`Categorical.as_unordered` (:issue:`37981`, :issue:`41118`, :issue:`41133`, :issue:`47834`)
Expand All @@ -475,7 +477,7 @@ Removal of prior version deprecations/changes
- Changed the behavior of :meth:`Index.reindex`, :meth:`Series.reindex`, and :meth:`DataFrame.reindex` with a ``datetime64`` dtype and a ``datetime.date`` object for ``fill_value``; these are no longer considered equivalent to ``datetime.datetime`` objects so the reindex casts to object dtype (:issue:`39767`)
- Changed behavior of :meth:`SparseArray.astype` when given a dtype that is not explicitly ``SparseDtype``, cast to the exact requested dtype rather than silently using a ``SparseDtype`` instead (:issue:`34457`)
- Changed behavior of :meth:`Index.ravel` to return a view on the original :class:`Index` instead of a ``np.ndarray`` (:issue:`36900`)
- Changed behavior of :meth:`Index.to_frame` with explicit ``name=None`` to use ``None`` for the column name instead of the index's name or default ``0`` (:issue:`45523`)
- Changed behavior of :meth:`Series.to_frame` and :meth:`Index.to_frame` with explicit ``name=None`` to use ``None`` for the column name instead of the index's name or default ``0`` (:issue:`45523`)
- Changed behavior of :class:`DataFrame` constructor given floating-point ``data`` and an integer ``dtype``, when the data cannot be cast losslessly, the floating point dtype is retained, matching :class:`Series` behavior (:issue:`41170`)
- Changed behavior of :class:`Index` constructor when given a ``np.ndarray`` with object-dtype containing numeric entries; this now retains object dtype rather than inferring a numeric dtype, consistent with :class:`Series` behavior (:issue:`42870`)
- Changed behavior of :meth:`Index.__and__`, :meth:`Index.__or__` and :meth:`Index.__xor__` to behave as logical operations (matching :class:`Series` behavior) instead of aliases for set operations (:issue:`37374`)
Expand Down
7 changes: 1 addition & 6 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2776,12 +2776,7 @@ def to_markdown(
**kwargs,
) -> str | None:
if "showindex" in kwargs:
warnings.warn(
"'showindex' is deprecated. Only 'index' will be used "
"in a future version. Use 'index' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
raise ValueError("Pass 'index' instead of 'showindex")

kwargs.setdefault("headers", "keys")
kwargs.setdefault("tablefmt", "pipe")
Expand Down
49 changes: 1 addition & 48 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8231,9 +8231,7 @@ def between_time(
self: NDFrameT,
start_time,
end_time,
include_start: bool_t | lib.NoDefault = lib.no_default,
include_end: bool_t | lib.NoDefault = lib.no_default,
inclusive: IntervalClosedType | None = None,
inclusive: IntervalClosedType = "both",
axis: Axis | None = None,
) -> NDFrameT:
"""
Expand All @@ -8248,20 +8246,6 @@ def between_time(
Initial time as a time filter limit.
end_time : datetime.time or str
End time as a time filter limit.
include_start : bool, default True
Whether the start time needs to be included in the result.

.. deprecated:: 1.4.0
Arguments `include_start` and `include_end` have been deprecated
to standardize boundary inputs. Use `inclusive` instead, to set
each bound as closed or open.
include_end : bool, default True
Whether the end time needs to be included in the result.

.. deprecated:: 1.4.0
Arguments `include_start` and `include_end` have been deprecated
to standardize boundary inputs. Use `inclusive` instead, to set
each bound as closed or open.
inclusive : {"both", "neither", "left", "right"}, default "both"
Include boundaries; whether to set each bound as closed or open.
axis : {0 or 'index', 1 or 'columns'}, default 0
Expand Down Expand Up @@ -8318,37 +8302,6 @@ def between_time(
if not isinstance(index, DatetimeIndex):
raise TypeError("Index must be DatetimeIndex")

old_include_arg_used = (include_start != lib.no_default) or (
include_end != lib.no_default
)

if old_include_arg_used and inclusive is not None:
raise ValueError(
"Deprecated arguments `include_start` and `include_end` "
"cannot be passed if `inclusive` has been given."
)
# If any of the deprecated arguments ('include_start', 'include_end')
# have been passed
if old_include_arg_used:
warnings.warn(
"`include_start` and `include_end` are deprecated in "
"favour of `inclusive`.",
FutureWarning,
stacklevel=find_stack_level(),
)
left = True if include_start is lib.no_default else include_start
right = True if include_end is lib.no_default else include_end

inc_dict: dict[tuple[bool_t, bool_t], IntervalClosedType] = {
(True, True): "both",
(True, False): "left",
(False, True): "right",
(False, False): "neither",
}
inclusive = inc_dict[(left, right)]
elif inclusive is None:
# On arg removal inclusive can default to "both"
inclusive = "both"
left_inclusive, right_inclusive = validate_inclusive(inclusive)
indexer = index.indexer_between_time(
start_time,
Expand Down
11 changes: 0 additions & 11 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,17 +1848,6 @@ def to_frame(self, name: Hashable = lib.no_default) -> DataFrame:
1 b
2 c
"""
if name is None:
warnings.warn(
"Explicitly passing `name=None` currently preserves the Series' name "
"or uses a default name of 0. This behaviour is deprecated, and in "
"the future `None` will be used as the name of the resulting "
"DataFrame column.",
FutureWarning,
stacklevel=find_stack_level(),
)
name = lib.no_default

columns: Index
if name is lib.no_default:
name = self.name
Expand Down
74 changes: 1 addition & 73 deletions pandas/tests/frame/methods/test_between_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,7 @@ def test_between_time_datetimeindex(self):
tm.assert_frame_equal(result, expected2)
assert len(result) == 12

@pytest.mark.parametrize("include_start", [True, False])
@pytest.mark.parametrize("include_end", [True, False])
def test_between_time_warn(self, include_start, include_end, frame_or_series):
# GH40245
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
ts = DataFrame(np.random.randn(len(rng), 2), index=rng)
ts = tm.get_obj(ts, frame_or_series)

stime = time(0, 0)
etime = time(1, 0)

match = (
"`include_start` and `include_end` "
"are deprecated in favour of `inclusive`."
)
with tm.assert_produces_warning(FutureWarning, match=match):
_ = ts.between_time(stime, etime, include_start, include_end)

def test_between_time_incorr_arg_inclusive(self):
def test_between_time_incorrect_arg_inclusive(self):
# GH40245
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
ts = DataFrame(np.random.randn(len(rng), 2), index=rng)
Expand All @@ -233,57 +215,3 @@ def test_between_time_incorr_arg_inclusive(self):
msg = "Inclusive has to be either 'both', 'neither', 'left' or 'right'"
with pytest.raises(ValueError, match=msg):
ts.between_time(stime, etime, inclusive=inclusive)

@pytest.mark.parametrize(
"include_start, include_end", [(True, None), (True, True), (None, True)]
)
def test_between_time_incompatiable_args_given(self, include_start, include_end):
# GH40245
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
ts = DataFrame(np.random.randn(len(rng), 2), index=rng)

stime = time(0, 0)
etime = time(1, 0)
msg = (
"Deprecated arguments `include_start` and `include_end` cannot be "
"passed if `inclusive` has been given."
)
with pytest.raises(ValueError, match=msg):
ts.between_time(stime, etime, include_start, include_end, inclusive="left")

def test_between_time_same_functionality_old_and_new_args(self):
# GH40245
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
ts = DataFrame(np.random.randn(len(rng), 2), index=rng)
stime = time(0, 0)
etime = time(1, 0)
match = (
"`include_start` and `include_end` "
"are deprecated in favour of `inclusive`."
)

result = ts.between_time(stime, etime)
expected = ts.between_time(stime, etime, inclusive="both")
tm.assert_frame_equal(result, expected)

with tm.assert_produces_warning(FutureWarning, match=match):
result = ts.between_time(stime, etime, include_start=False)
expected = ts.between_time(stime, etime, inclusive="right")
tm.assert_frame_equal(result, expected)

with tm.assert_produces_warning(FutureWarning, match=match):
result = ts.between_time(stime, etime, include_end=False)
expected = ts.between_time(stime, etime, inclusive="left")
tm.assert_frame_equal(result, expected)

with tm.assert_produces_warning(FutureWarning, match=match):
result = ts.between_time(
stime, etime, include_start=False, include_end=False
)
expected = ts.between_time(stime, etime, inclusive="neither")
tm.assert_frame_equal(result, expected)

with tm.assert_produces_warning(FutureWarning, match=match):
result = ts.between_time(stime, etime, include_start=True, include_end=True)
expected = ts.between_time(stime, etime, inclusive="both")
tm.assert_frame_equal(result, expected)
45 changes: 17 additions & 28 deletions pandas/tests/io/formats/test_to_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest

import pandas as pd
import pandas._testing as tm

pytest.importorskip("tabulate")

Expand Down Expand Up @@ -67,35 +66,25 @@ def test_no_buf():
)


@pytest.mark.parametrize("index", [True, False, None])
@pytest.mark.parametrize("showindex", [True, False, None])
def test_index(index, showindex):
@pytest.mark.parametrize("index", [True, False])
def test_index(index):
# GH 32667
kwargs = {}
if index is not None:
kwargs["index"] = index
if showindex is not None:
kwargs["showindex"] = showindex

df = pd.DataFrame([1, 2, 3])
yes_index_result = (
"| | 0 |\n|---:|----:|\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |"
)
no_index_result = "| 0 |\n|----:|\n| 1 |\n| 2 |\n| 3 |"

warning = FutureWarning if "showindex" in kwargs else None
with tm.assert_produces_warning(warning):
result = df.to_markdown(**kwargs)

if "showindex" in kwargs:
# give showindex higher priority if specified
if showindex:
expected = yes_index_result
else:
expected = no_index_result

result = df.to_markdown(index=index)

if index:
expected = (
"| | 0 |\n|---:|----:|\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |"
)
else:
if index in [True, None]:
expected = yes_index_result
else:
expected = no_index_result
expected = "| 0 |\n|----:|\n| 1 |\n| 2 |\n| 3 |"
assert result == expected


def test_showindex_disallowed_in_kwargs():
# GH 32667; disallowing showindex in kwargs enforced in 2.0
df = pd.DataFrame([1, 2, 3])
with pytest.raises(ValueError, match="Pass 'index' instead of 'showindex"):
df.to_markdown(index=True, showindex=True)
13 changes: 5 additions & 8 deletions pandas/tests/series/methods/test_to_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ class TestToFrame:
def test_to_frame_respects_name_none(self):
# GH#44212 if we explicitly pass name=None, then that should be respected,
# not changed to 0
# GH-45448 this is first deprecated to only change in the future
# GH-45448 this is first deprecated & enforced in 2.0
ser = Series(range(3))
with tm.assert_produces_warning(FutureWarning):
result = ser.to_frame(None)
result = ser.to_frame(None)

# exp_index = Index([None], dtype=object)
exp_index = Index([0])
exp_index = Index([None], dtype=object)
tm.assert_index_equal(result.columns, exp_index)

with tm.assert_produces_warning(FutureWarning):
result = ser.rename("foo").to_frame(None)
exp_index = Index(["foo"], dtype=object)
result = ser.rename("foo").to_frame(None)
exp_index = Index([None], dtype=object)
tm.assert_index_equal(result.columns, exp_index)

def test_to_frame(self, datetime_series):
Expand Down