Skip to content

Commit d69e63d

Browse files
authored
DEPR: Enforce deprecations (pandas-dev#49589)
* Disallow showindex in to_markdown * Series.to_frame(name=None) * DataFrame.between_times(include_*)
1 parent 4117f98 commit d69e63d

File tree

7 files changed

+28
-175
lines changed

7 files changed

+28
-175
lines changed

doc/source/whatsnew/v2.0.0.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ Removal of prior version deprecations/changes
434434
- Disallow passing abbreviations for ``orient`` in :meth:`DataFrame.to_dict` (:issue:`32516`)
435435
- Removed ``get_offset`` in favor of :func:`to_offset` (:issue:`30340`)
436436
- Removed the ``warn`` keyword in :func:`infer_freq` (:issue:`45947`)
437+
- Removed the ``include_start`` and ``include_end`` arguments in :meth:`DataFrame.between_time` in favor of ``inclusive`` (:issue:`43248`)
437438
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
438439
- Removed the ``truediv`` keyword from :func:`eval` (:issue:`29812`)
439440
- Removed the ``pandas.datetime`` submodule (:issue:`30489`)
@@ -457,6 +458,7 @@ Removal of prior version deprecations/changes
457458
- Enforced disallowing :func:`merge` to produce duplicated columns through the ``suffixes`` keyword and already existing columns (:issue:`22818`)
458459
- Enforced disallowing using :func:`merge` or :func:`join` on a different number of levels (:issue:`34862`)
459460
- Enforced disallowing ``value_name`` argument in :func:`DataFrame.melt` to match an element in the :class:`DataFrame` columns (:issue:`35003`)
461+
- Enforced disallowing passing ``showindex`` into ``**kwargs`` in :func:`DataFrame.to_markdown` and :func:`Series.to_markdown` in favor of ``index`` (:issue:`33091`)
460462
- Removed setting Categorical._codes directly (:issue:`41429`)
461463
- Removed setting Categorical.categories directly (:issue:`47834`)
462464
- 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`)
@@ -475,7 +477,7 @@ Removal of prior version deprecations/changes
475477
- 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`)
476478
- 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`)
477479
- Changed behavior of :meth:`Index.ravel` to return a view on the original :class:`Index` instead of a ``np.ndarray`` (:issue:`36900`)
478-
- 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`)
480+
- 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`)
479481
- 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`)
480482
- 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`)
481483
- 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`)

pandas/core/frame.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -2776,12 +2776,7 @@ def to_markdown(
27762776
**kwargs,
27772777
) -> str | None:
27782778
if "showindex" in kwargs:
2779-
warnings.warn(
2780-
"'showindex' is deprecated. Only 'index' will be used "
2781-
"in a future version. Use 'index' to silence this warning.",
2782-
FutureWarning,
2783-
stacklevel=find_stack_level(),
2784-
)
2779+
raise ValueError("Pass 'index' instead of 'showindex")
27852780

27862781
kwargs.setdefault("headers", "keys")
27872782
kwargs.setdefault("tablefmt", "pipe")

pandas/core/generic.py

+1-48
Original file line numberDiff line numberDiff line change
@@ -8231,9 +8231,7 @@ def between_time(
82318231
self: NDFrameT,
82328232
start_time,
82338233
end_time,
8234-
include_start: bool_t | lib.NoDefault = lib.no_default,
8235-
include_end: bool_t | lib.NoDefault = lib.no_default,
8236-
inclusive: IntervalClosedType | None = None,
8234+
inclusive: IntervalClosedType = "both",
82378235
axis: Axis | None = None,
82388236
) -> NDFrameT:
82398237
"""
@@ -8248,20 +8246,6 @@ def between_time(
82488246
Initial time as a time filter limit.
82498247
end_time : datetime.time or str
82508248
End time as a time filter limit.
8251-
include_start : bool, default True
8252-
Whether the start time needs to be included in the result.
8253-
8254-
.. deprecated:: 1.4.0
8255-
Arguments `include_start` and `include_end` have been deprecated
8256-
to standardize boundary inputs. Use `inclusive` instead, to set
8257-
each bound as closed or open.
8258-
include_end : bool, default True
8259-
Whether the end time needs to be included in the result.
8260-
8261-
.. deprecated:: 1.4.0
8262-
Arguments `include_start` and `include_end` have been deprecated
8263-
to standardize boundary inputs. Use `inclusive` instead, to set
8264-
each bound as closed or open.
82658249
inclusive : {"both", "neither", "left", "right"}, default "both"
82668250
Include boundaries; whether to set each bound as closed or open.
82678251
axis : {0 or 'index', 1 or 'columns'}, default 0
@@ -8318,37 +8302,6 @@ def between_time(
83188302
if not isinstance(index, DatetimeIndex):
83198303
raise TypeError("Index must be DatetimeIndex")
83208304

8321-
old_include_arg_used = (include_start != lib.no_default) or (
8322-
include_end != lib.no_default
8323-
)
8324-
8325-
if old_include_arg_used and inclusive is not None:
8326-
raise ValueError(
8327-
"Deprecated arguments `include_start` and `include_end` "
8328-
"cannot be passed if `inclusive` has been given."
8329-
)
8330-
# If any of the deprecated arguments ('include_start', 'include_end')
8331-
# have been passed
8332-
if old_include_arg_used:
8333-
warnings.warn(
8334-
"`include_start` and `include_end` are deprecated in "
8335-
"favour of `inclusive`.",
8336-
FutureWarning,
8337-
stacklevel=find_stack_level(),
8338-
)
8339-
left = True if include_start is lib.no_default else include_start
8340-
right = True if include_end is lib.no_default else include_end
8341-
8342-
inc_dict: dict[tuple[bool_t, bool_t], IntervalClosedType] = {
8343-
(True, True): "both",
8344-
(True, False): "left",
8345-
(False, True): "right",
8346-
(False, False): "neither",
8347-
}
8348-
inclusive = inc_dict[(left, right)]
8349-
elif inclusive is None:
8350-
# On arg removal inclusive can default to "both"
8351-
inclusive = "both"
83528305
left_inclusive, right_inclusive = validate_inclusive(inclusive)
83538306
indexer = index.indexer_between_time(
83548307
start_time,

pandas/core/series.py

-11
Original file line numberDiff line numberDiff line change
@@ -1848,17 +1848,6 @@ def to_frame(self, name: Hashable = lib.no_default) -> DataFrame:
18481848
1 b
18491849
2 c
18501850
"""
1851-
if name is None:
1852-
warnings.warn(
1853-
"Explicitly passing `name=None` currently preserves the Series' name "
1854-
"or uses a default name of 0. This behaviour is deprecated, and in "
1855-
"the future `None` will be used as the name of the resulting "
1856-
"DataFrame column.",
1857-
FutureWarning,
1858-
stacklevel=find_stack_level(),
1859-
)
1860-
name = lib.no_default
1861-
18621851
columns: Index
18631852
if name is lib.no_default:
18641853
name = self.name

pandas/tests/frame/methods/test_between_time.py

+1-73
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,7 @@ def test_between_time_datetimeindex(self):
204204
tm.assert_frame_equal(result, expected2)
205205
assert len(result) == 12
206206

207-
@pytest.mark.parametrize("include_start", [True, False])
208-
@pytest.mark.parametrize("include_end", [True, False])
209-
def test_between_time_warn(self, include_start, include_end, frame_or_series):
210-
# GH40245
211-
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
212-
ts = DataFrame(np.random.randn(len(rng), 2), index=rng)
213-
ts = tm.get_obj(ts, frame_or_series)
214-
215-
stime = time(0, 0)
216-
etime = time(1, 0)
217-
218-
match = (
219-
"`include_start` and `include_end` "
220-
"are deprecated in favour of `inclusive`."
221-
)
222-
with tm.assert_produces_warning(FutureWarning, match=match):
223-
_ = ts.between_time(stime, etime, include_start, include_end)
224-
225-
def test_between_time_incorr_arg_inclusive(self):
207+
def test_between_time_incorrect_arg_inclusive(self):
226208
# GH40245
227209
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
228210
ts = DataFrame(np.random.randn(len(rng), 2), index=rng)
@@ -233,57 +215,3 @@ def test_between_time_incorr_arg_inclusive(self):
233215
msg = "Inclusive has to be either 'both', 'neither', 'left' or 'right'"
234216
with pytest.raises(ValueError, match=msg):
235217
ts.between_time(stime, etime, inclusive=inclusive)
236-
237-
@pytest.mark.parametrize(
238-
"include_start, include_end", [(True, None), (True, True), (None, True)]
239-
)
240-
def test_between_time_incompatiable_args_given(self, include_start, include_end):
241-
# GH40245
242-
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
243-
ts = DataFrame(np.random.randn(len(rng), 2), index=rng)
244-
245-
stime = time(0, 0)
246-
etime = time(1, 0)
247-
msg = (
248-
"Deprecated arguments `include_start` and `include_end` cannot be "
249-
"passed if `inclusive` has been given."
250-
)
251-
with pytest.raises(ValueError, match=msg):
252-
ts.between_time(stime, etime, include_start, include_end, inclusive="left")
253-
254-
def test_between_time_same_functionality_old_and_new_args(self):
255-
# GH40245
256-
rng = date_range("1/1/2000", "1/5/2000", freq="5min")
257-
ts = DataFrame(np.random.randn(len(rng), 2), index=rng)
258-
stime = time(0, 0)
259-
etime = time(1, 0)
260-
match = (
261-
"`include_start` and `include_end` "
262-
"are deprecated in favour of `inclusive`."
263-
)
264-
265-
result = ts.between_time(stime, etime)
266-
expected = ts.between_time(stime, etime, inclusive="both")
267-
tm.assert_frame_equal(result, expected)
268-
269-
with tm.assert_produces_warning(FutureWarning, match=match):
270-
result = ts.between_time(stime, etime, include_start=False)
271-
expected = ts.between_time(stime, etime, inclusive="right")
272-
tm.assert_frame_equal(result, expected)
273-
274-
with tm.assert_produces_warning(FutureWarning, match=match):
275-
result = ts.between_time(stime, etime, include_end=False)
276-
expected = ts.between_time(stime, etime, inclusive="left")
277-
tm.assert_frame_equal(result, expected)
278-
279-
with tm.assert_produces_warning(FutureWarning, match=match):
280-
result = ts.between_time(
281-
stime, etime, include_start=False, include_end=False
282-
)
283-
expected = ts.between_time(stime, etime, inclusive="neither")
284-
tm.assert_frame_equal(result, expected)
285-
286-
with tm.assert_produces_warning(FutureWarning, match=match):
287-
result = ts.between_time(stime, etime, include_start=True, include_end=True)
288-
expected = ts.between_time(stime, etime, inclusive="both")
289-
tm.assert_frame_equal(result, expected)

pandas/tests/io/formats/test_to_markdown.py

+17-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44

55
import pandas as pd
6-
import pandas._testing as tm
76

87
pytest.importorskip("tabulate")
98

@@ -67,35 +66,25 @@ def test_no_buf():
6766
)
6867

6968

70-
@pytest.mark.parametrize("index", [True, False, None])
71-
@pytest.mark.parametrize("showindex", [True, False, None])
72-
def test_index(index, showindex):
69+
@pytest.mark.parametrize("index", [True, False])
70+
def test_index(index):
7371
# GH 32667
74-
kwargs = {}
75-
if index is not None:
76-
kwargs["index"] = index
77-
if showindex is not None:
78-
kwargs["showindex"] = showindex
7972

8073
df = pd.DataFrame([1, 2, 3])
81-
yes_index_result = (
82-
"| | 0 |\n|---:|----:|\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |"
83-
)
84-
no_index_result = "| 0 |\n|----:|\n| 1 |\n| 2 |\n| 3 |"
85-
86-
warning = FutureWarning if "showindex" in kwargs else None
87-
with tm.assert_produces_warning(warning):
88-
result = df.to_markdown(**kwargs)
89-
90-
if "showindex" in kwargs:
91-
# give showindex higher priority if specified
92-
if showindex:
93-
expected = yes_index_result
94-
else:
95-
expected = no_index_result
74+
75+
result = df.to_markdown(index=index)
76+
77+
if index:
78+
expected = (
79+
"| | 0 |\n|---:|----:|\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |"
80+
)
9681
else:
97-
if index in [True, None]:
98-
expected = yes_index_result
99-
else:
100-
expected = no_index_result
82+
expected = "| 0 |\n|----:|\n| 1 |\n| 2 |\n| 3 |"
10183
assert result == expected
84+
85+
86+
def test_showindex_disallowed_in_kwargs():
87+
# GH 32667; disallowing showindex in kwargs enforced in 2.0
88+
df = pd.DataFrame([1, 2, 3])
89+
with pytest.raises(ValueError, match="Pass 'index' instead of 'showindex"):
90+
df.to_markdown(index=True, showindex=True)

pandas/tests/series/methods/test_to_frame.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ class TestToFrame:
1010
def test_to_frame_respects_name_none(self):
1111
# GH#44212 if we explicitly pass name=None, then that should be respected,
1212
# not changed to 0
13-
# GH-45448 this is first deprecated to only change in the future
13+
# GH-45448 this is first deprecated & enforced in 2.0
1414
ser = Series(range(3))
15-
with tm.assert_produces_warning(FutureWarning):
16-
result = ser.to_frame(None)
15+
result = ser.to_frame(None)
1716

18-
# exp_index = Index([None], dtype=object)
19-
exp_index = Index([0])
17+
exp_index = Index([None], dtype=object)
2018
tm.assert_index_equal(result.columns, exp_index)
2119

22-
with tm.assert_produces_warning(FutureWarning):
23-
result = ser.rename("foo").to_frame(None)
24-
exp_index = Index(["foo"], dtype=object)
20+
result = ser.rename("foo").to_frame(None)
21+
exp_index = Index([None], dtype=object)
2522
tm.assert_index_equal(result.columns, exp_index)
2623

2724
def test_to_frame(self, datetime_series):

0 commit comments

Comments
 (0)