Skip to content

DEPR: Period[B] #53511

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 12 commits into from
Jul 24, 2023
Prev Previous commit
Next Next commit
Merge branch 'main' into depr-period-b
  • Loading branch information
jbrockmendel committed Jul 18, 2023
commit b89e40df7d07ea0af38b8811d15f4e65a8cd8589
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ Deprecations
- Deprecated unused "closed" keyword in the :class:`TimedeltaIndex` constructor (:issue:`52628`)
- Deprecated logical operation between two non boolean :class:`Series` with different indexes always coercing the result to bool dtype. In a future version, this will maintain the return type of the inputs. (:issue:`52500`, :issue:`52538`)
- Deprecated :class:`Period` and :class:`PeriodDtype` with ``BDay`` freq, use a :class:`DatetimeIndex` with ``BDay`` freq instead (:issue:`53446`)
- Deprecated :func:`value_counts`, use ``pd.Series(obj).value_counts()`` instead (:issue:`47862`)
- Deprecated :meth:`Series.first` and :meth:`DataFrame.first` (please create a mask and filter using ``.loc`` instead) (:issue:`45908`)
- Deprecated :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`53631`)
- Deprecated :meth:`Series.last` and :meth:`DataFrame.last` (please create a mask and filter using ``.loc`` instead) (:issue:`53692`)
Expand Down
44 changes: 3 additions & 41 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,46 +134,9 @@ def test_period_index_length(self):
with pytest.raises(ValueError, match=msg):
PeriodIndex(vals)

# @pytest.mark.filterwarnings("ignore:Period with BDay freq:FutureWarning")
def test_fields(self):
# year, month, day, hour, minute
# second, weekofyear, week, dayofweek, weekday, dayofyear, quarter
# qyear
pi = period_range(freq="A", start="1/1/2001", end="12/1/2005")
self._check_all_fields(pi)

pi = period_range(freq="Q", start="1/1/2001", end="12/1/2002")
self._check_all_fields(pi)

pi = period_range(freq="M", start="1/1/2001", end="1/1/2002")
self._check_all_fields(pi)

pi = period_range(freq="D", start="12/1/2001", end="6/1/2001")
self._check_all_fields(pi)

msg2 = "Period with BDay freq is deprecated"

with tm.assert_produces_warning(FutureWarning, match=msg2):
pi = period_range(freq="B", start="12/1/2001", end="6/1/2001")
self._check_all_fields(pi)

pi = period_range(freq="H", start="12/31/2001", end="1/1/2002 23:00")
self._check_all_fields(pi)

pi = period_range(freq="Min", start="12/31/2001", end="1/1/2002 00:20")
self._check_all_fields(pi)

pi = period_range(
freq="S", start="12/31/2001 00:00:00", end="12/31/2001 00:05:00"
)
self._check_all_fields(pi)

end_intv = Period("2006-12-31", "W")
i1 = period_range(end=end_intv, periods=10)
self._check_all_fields(i1)

def _check_all_fields(self, periodindex):
fields = [
@pytest.mark.parametrize(
"field",
[
"year",
"month",
"day",
Expand All @@ -198,7 +161,6 @@ def _check_all_fields(self, periodindex):
period_range(freq="Q", start="1/1/2001", end="12/1/2002"),
period_range(freq="M", start="1/1/2001", end="1/1/2002"),
period_range(freq="D", start="12/1/2001", end="6/1/2001"),
period_range(freq="B", start="12/1/2001", end="6/1/2001"),
period_range(freq="H", start="12/31/2001", end="1/1/2002 23:00"),
period_range(freq="Min", start="12/31/2001", end="1/1/2002 00:20"),
period_range(
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ def test_xcompat_plot_period(self):
ax = df.plot()
lines = ax.get_lines()
assert not isinstance(lines[0].get_xdata(), PeriodIndex)
msg = r"PeriodDtype\[B\] is deprecated "
with tm.assert_produces_warning(FutureWarning, match=msg):
assert isinstance(PeriodIndex(lines[0].get_xdata()), PeriodIndex)
self._check_ticks_props(ax, xrot=0)
_check_ticks_props(ax, xrot=0)

def test_period_compat(self):
# GH 9012
Expand Down
30 changes: 19 additions & 11 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,21 @@ def test_dataframe(self):
@pytest.mark.filterwarnings(
"ignore:Period with BDay freq is deprecated:FutureWarning"
)
def test_axis_limits(self):
def _test(ax):
xlim = ax.get_xlim()
ax.set_xlim(xlim[0] - 5, xlim[1] + 10)
result = ax.get_xlim()
assert result[0] == xlim[0] - 5
assert result[1] == xlim[1] + 10
@pytest.mark.parametrize(
"obj",
[
tm.makeTimeSeries(),
DataFrame({"a": tm.makeTimeSeries(), "b": tm.makeTimeSeries() + 1}),
],
)
def test_axis_limits(self, obj):
_, ax = mpl.pyplot.subplots()
obj.plot(ax=ax)
xlim = ax.get_xlim()
ax.set_xlim(xlim[0] - 5, xlim[1] + 10)
result = ax.get_xlim()
assert result[0] == xlim[0] - 5
assert result[1] == xlim[1] + 10

# string
expected = (Period("1/1/2000", ax.freq), Period("4/1/2000", ax.freq))
Expand Down Expand Up @@ -814,10 +822,10 @@ def test_mixed_freq_irreg_period(self):
msg = r"PeriodDtype\[B\] is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
rng = period_range("1/3/2000", periods=30, freq="B")
ps = Series(np.random.randn(len(rng)), rng)
_, ax = self.plt.subplots()
irreg.plot(ax=ax)
ps.plot(ax=ax)
ps = Series(np.random.randn(len(rng)), rng)
_, ax = mpl.pyplot.subplots()
irreg.plot(ax=ax)
ps.plot(ax=ax)

def test_mixed_freq_shared_ax(self):
# GH13341, using sharex=True
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.