-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: attrs #52152
Closed
Closed
DEPR: attrs #52152
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b338f8d
DEPR: attrs
jbrockmendel 5ee0aa3
Merge branch 'main' into depr-attrs
jbrockmendel cc562c3
ignore pickle warning
jbrockmendel 1f75880
Merge branch 'main' into depr-attrs
jbrockmendel 2a89010
Merge branch 'main' into depr-attrs
jbrockmendel 5517c7c
Merge branch 'main' into depr-attrs
jbrockmendel ed9f73c
Merge branch 'main' into depr-attrs
jbrockmendel 28e5165
catch warning in new tests
jbrockmendel 3087ced
Merge branch 'main' into depr-attrs
jbrockmendel 3fac5df
Merge branch 'main' into depr-attrs
jbrockmendel 4484b37
catch in new test
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import pytest | ||
|
||
import pandas as pd | ||
import pandas._testing as tm | ||
|
||
# TODO: | ||
# * Binary methods (mul, div, etc.) | ||
|
@@ -457,19 +458,26 @@ def test_finalize_called(ndframe_method): | |
cls, init_args, method = ndframe_method | ||
ndframe = cls(*init_args) | ||
|
||
ndframe.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
ndframe.attrs = {"a": 1} | ||
result = method(ndframe) | ||
|
||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
@not_implemented_mark | ||
def test_finalize_called_eval_numexpr(): | ||
pytest.importorskip("numexpr") | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
|
||
df = pd.DataFrame({"A": [1, 2]}) | ||
df.attrs["A"] = 1 | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
df.attrs["A"] = 1 | ||
result = df.eval("A + 1", engine="numexpr") | ||
assert result.attrs == {"A": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"A": 1} | ||
|
||
|
||
# ---------------------------------------------------------------------------- | ||
|
@@ -491,13 +499,18 @@ def test_finalize_called_eval_numexpr(): | |
], | ||
ids=lambda x: f"({type(x[0]).__name__},{type(x[1]).__name__})", | ||
) | ||
@pytest.mark.filterwarnings("ignore:Series.attrs is deprecated:FutureWarning") | ||
def test_binops(request, args, annotate, all_binary_operators): | ||
# This generates 624 tests... Is that needed? | ||
left, right = args | ||
|
||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
if isinstance(left, (pd.DataFrame, pd.Series)): | ||
left.attrs = {} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
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. can probably remove this if you're already filtering the warnings from the test? |
||
left.attrs = {} | ||
if isinstance(right, (pd.DataFrame, pd.Series)): | ||
right.attrs = {} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
right.attrs = {} | ||
|
||
if annotate == "left" and isinstance(left, int): | ||
pytest.skip("left is an int and doesn't support .attrs") | ||
|
@@ -552,9 +565,11 @@ def test_binops(request, args, annotate, all_binary_operators): | |
) | ||
) | ||
if annotate in {"left", "both"} and not isinstance(left, int): | ||
left.attrs = {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
left.attrs = {"a": 1} | ||
if annotate in {"right", "both"} and not isinstance(right, int): | ||
right.attrs = {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
right.attrs = {"a": 1} | ||
|
||
is_cmp = all_binary_operators in [ | ||
operator.eq, | ||
|
@@ -571,7 +586,8 @@ def test_binops(request, args, annotate, all_binary_operators): | |
right, left = right.align(left, axis=1, copy=False) | ||
|
||
result = all_binary_operators(left, right) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
# ---------------------------------------------------------------------------- | ||
|
@@ -633,9 +649,12 @@ def test_binops(request, args, annotate, all_binary_operators): | |
) | ||
def test_string_method(method): | ||
s = pd.Series(["a1"]) | ||
s.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
s.attrs = {"a": 1} | ||
result = method(s.str) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -655,9 +674,12 @@ def test_string_method(method): | |
) | ||
def test_datetime_method(method): | ||
s = pd.Series(pd.date_range("2000", periods=4)) | ||
s.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
s.attrs = {"a": 1} | ||
result = method(s.dt) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -692,27 +714,36 @@ def test_datetime_method(method): | |
) | ||
def test_datetime_property(attr): | ||
s = pd.Series(pd.date_range("2000", periods=4)) | ||
s.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
s.attrs = {"a": 1} | ||
result = getattr(s.dt, attr) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"attr", ["days", "seconds", "microseconds", "nanoseconds", "components"] | ||
) | ||
def test_timedelta_property(attr): | ||
s = pd.Series(pd.timedelta_range("2000", periods=4)) | ||
s.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
s.attrs = {"a": 1} | ||
result = getattr(s.dt, attr) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
@pytest.mark.parametrize("method", [operator.methodcaller("total_seconds")]) | ||
def test_timedelta_methods(method): | ||
s = pd.Series(pd.timedelta_range("2000", periods=4)) | ||
s.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
s.attrs = {"a": 1} | ||
result = method(s.dt) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -732,9 +763,12 @@ def test_timedelta_methods(method): | |
@not_implemented_mark | ||
def test_categorical_accessor(method): | ||
s = pd.Series(["a", "b"], dtype="category") | ||
s.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
s.attrs = {"a": 1} | ||
result = method(s.cat) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
# ---------------------------------------------------------------------------- | ||
|
@@ -755,9 +789,12 @@ def test_categorical_accessor(method): | |
], | ||
) | ||
def test_groupby_finalize(obj, method): | ||
obj.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
obj.attrs = {"a": 1} | ||
result = method(obj.groupby([0, 0], group_keys=False)) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -777,9 +814,12 @@ def test_groupby_finalize(obj, method): | |
) | ||
@not_implemented_mark | ||
def test_groupby_finalize_not_implemented(obj, method): | ||
obj.attrs = {"a": 1} | ||
warn_msg = "(DataFrame|Series).attrs is deprecated" | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
obj.attrs = {"a": 1} | ||
result = method(obj.groupby([0, 0])) | ||
assert result.attrs == {"a": 1} | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
assert result.attrs == {"a": 1} | ||
|
||
|
||
def test_finalize_frame_series_name(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I am not sure that creating a subclass is the advice we want to give to users to retain the behaviour (generally users should be very wary about creating a custom subclass).
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.
That seems reasonable. Did you have something else in mind?
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.
No, I am not aware of a good alternative. But so that's the part we should discuss before deprecating it.