-
Notifications
You must be signed in to change notification settings - Fork 651
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
FIX-#4593: Ensure Modin warns when setting columns via attributes #4621
Changes from all commits
e8b5550
2962950
c000e49
e5afc1d
c233318
efb6fe7
2d21543
ded947c
b4654dd
0ed4d7b
5166bd3
79f67c2
5ea1a05
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import matplotlib | ||
import modin.pandas as pd | ||
import io | ||
import warnings | ||
|
||
from modin.pandas.test.utils import ( | ||
random_state, | ||
|
@@ -289,6 +290,36 @@ def test___setattr__mutating_column(): | |
df_equals(modin_df, pandas_df) | ||
assert modin_df.col0.equals(modin_df["col0"]) | ||
|
||
# Check that attempting to add a new col via attributes raises warning | ||
# and adds the provided list as a new attribute and not a column. | ||
with pytest.warns( | ||
UserWarning, | ||
match="Modin doesn't allow columns to be created via a new attribute name - see " | ||
+ "https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access", | ||
): | ||
modin_df.col1 = [4] | ||
|
||
with warnings.catch_warnings(): | ||
warnings.filterwarnings( | ||
Comment on lines
+302
to
+303
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. Why are we catching the warnings and filtering them out? Is this so ensure that only these warnings are thrown here? 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. Yes, only the warnings we care about will cause the test to fail if they were raised (they should not!). Other types of warnings we have no control over. They may or may not be raised (possibly depending on the environment), so we want to ignore them (filter them out). 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. Does it make sense? 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. Gotcha, makes sense |
||
action="error", | ||
message="Modin doesn't allow columns to be created via a new attribute name - see " | ||
+ "https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access", | ||
) | ||
modin_df.col1 = [5] | ||
modin_df.new_attr = 6 | ||
modin_df.col0 = 7 | ||
|
||
assert "new_attr" in dir( | ||
modin_df | ||
), "Modin attribute was not correctly added to the df." | ||
assert ( | ||
"new_attr" not in modin_df | ||
), "New attribute was not correctly added to columns." | ||
assert modin_df.new_attr == 6, "Modin attribute value was set incorrectly." | ||
assert isinstance( | ||
modin_df.col0, pd.Series | ||
), "Scalar was not broadcasted properly to an existing column." | ||
|
||
|
||
@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys) | ||
def test_isin(data): | ||
|
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 could add an extra
elif
case that checks to see if the value the user is trying to setis_list_like()
here and throw the warning in this case.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 think replacement is sufficient rather than having both checks, right?
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.
Replacement is sufficient since
is_list_like()
will always be True forpandas.Series
.