-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
DEPR: Deprecate week, weekofyear in Series.dt,DatetimeIndex #33595
Changes from all commits
4007381
38efb17
f5b42b8
22c96f5
9688dd0
cd702eb
b4eb746
56874ec
0bda2e8
658506d
734ae8f
762dc81
b81536b
e87c26c
acf2bbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,8 +156,8 @@ def test_datetimeindex_accessors(self): | |
assert dti.dayofyear[0] == 1 | ||
assert dti.dayofyear[120] == 121 | ||
|
||
assert dti.weekofyear[0] == 1 | ||
assert dti.weekofyear[120] == 18 | ||
assert dti.isocalendar().week[0] == 1 | ||
assert dti.isocalendar().week[120] == 18 | ||
|
||
assert dti.quarter[0] == 1 | ||
assert dti.quarter[120] == 2 | ||
|
@@ -192,7 +192,7 @@ def test_datetimeindex_accessors(self): | |
assert len(dti.microsecond) == 365 | ||
assert len(dti.dayofweek) == 365 | ||
assert len(dti.dayofyear) == 365 | ||
assert len(dti.weekofyear) == 365 | ||
assert len(dti.isocalendar()) == 365 | ||
assert len(dti.quarter) == 365 | ||
assert len(dti.is_month_start) == 365 | ||
assert len(dti.is_month_end) == 365 | ||
|
@@ -205,6 +205,9 @@ def test_datetimeindex_accessors(self): | |
|
||
# non boolean accessors -> return Index | ||
for accessor in DatetimeIndex._field_ops: | ||
if accessor in ["week", "weekofyear"]: | ||
# GH#33595 Deprecate week and weekofyear | ||
continue | ||
res = getattr(dti, accessor) | ||
assert len(res) == 365 | ||
assert isinstance(res, Index) | ||
|
@@ -285,7 +288,7 @@ def test_datetimeindex_accessors(self): | |
dates = ["2013/12/29", "2013/12/30", "2013/12/31"] | ||
dates = DatetimeIndex(dates, tz="Europe/Brussels") | ||
expected = [52, 1, 1] | ||
assert dates.weekofyear.tolist() == expected | ||
assert dates.isocalendar().week.tolist() == expected | ||
assert [d.weekofyear for d in dates] == expected | ||
|
||
# GH 12806 | ||
|
@@ -383,6 +386,15 @@ def test_iter_readonly(): | |
list(dti) | ||
|
||
|
||
def test_week_and_weekofyear_are_deprecated(): | ||
# GH#33595 Deprecate week and weekofyear | ||
idx = pd.date_range(start="2019-12-29", freq="D", periods=4) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
with tm.assert_produces_warning(FutureWarning): | ||
idx.week | ||
with tm.assert_produces_warning(FutureWarning): | ||
idx.weekofyear | ||
|
||
|
||
def test_isocalendar_returns_correct_values_close_to_new_year_with_tz(): | ||
# GH 6538: Check that DatetimeIndex and its TimeStamp elements | ||
# return the same weekofyear accessor close to new year w/ tz | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,9 @@ def test_nat_vector_field_access(): | |
# on NaT/Timestamp for compat with datetime | ||
if field == "weekday": | ||
continue | ||
if field in ["week", "weekofyear"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should properly parameterize these tests (if you would like to make an issue would be great), PR even better :-> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im happy to make another PR, will wait until this is merged. |
||
# GH#33595 Deprecate week and weekofyear | ||
continue | ||
|
||
result = getattr(idx, field) | ||
expected = Index([getattr(x, field) for x in idx]) | ||
|
@@ -78,6 +81,9 @@ def test_nat_vector_field_access(): | |
# on NaT/Timestamp for compat with datetime | ||
if field == "weekday": | ||
continue | ||
if field in ["week", "weekofyear"]: | ||
# GH#33595 Deprecate week and weekofyear | ||
continue | ||
|
||
result = getattr(ser.dt, field) | ||
expected = [getattr(x, field) for x in idx] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,8 @@ def compare(s, name): | |
for s in cases: | ||
for prop in ok_for_dt: | ||
# we test freq below | ||
if prop != "freq": | ||
# we ignore week and weekofyear because they are deprecated | ||
if prop not in ["freq", "week", "weekofyear"]: | ||
compare(s, prop) | ||
|
||
for prop in ok_for_dt_methods: | ||
|
@@ -122,7 +123,8 @@ def compare(s, name): | |
for prop in ok_for_dt: | ||
|
||
# we test freq below | ||
if prop != "freq": | ||
# we ignore week and weekofyear because they are deprecated | ||
if prop not in ["freq", "week", "weekofyear"]: | ||
compare(s, prop) | ||
|
||
for prop in ok_for_dt_methods: | ||
|
@@ -687,3 +689,12 @@ def test_isocalendar(self, input_series, expected_output): | |
expected_output, columns=["year", "week", "day"], dtype="UInt32" | ||
) | ||
tm.assert_frame_equal(result, expected_frame) | ||
|
||
|
||
def test_week_and_weekofyear_are_deprecated(): | ||
# GH#33595 Deprecate week and weekofyear | ||
series = pd.to_datetime(pd.Series(["2020-01-01"])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
with tm.assert_produces_warning(FutureWarning): | ||
series.dt.week | ||
with tm.assert_produces_warning(FutureWarning): | ||
series.dt.weekofyear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do it like this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the current
week
accessor the array is converted to a float and masked if there are nans. This reproduces that behavior instead of passing back aUInt32
series.