Skip to content
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-#4672: Fix incorrect warning when setting frame.columns or frame.index #4721

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release_notes/release_notes-0.16.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Key Features and Updates
* FIX-#4491: Wait for all partitions in parallel in benchmark mode (#4656)
* FIX-#4358: MultiIndex `loc` shouldn't drop levels for full-key lookups (#4608)
* FIX-#4658: Expand exception handling for `read_*` functions from s3 storages (#4659)
* FIX-#4672: Fix incorrect warning when setting `frame.index` or `frame.columns` (#4721)
* Performance enhancements
* PERF-#4182: Add cell-wise execution for binary ops, fix bin ops for empty dataframes (#4391)
* PERF-#4288: Improve perf of `groupby.mean` for narrow data (#4591)
Expand Down
2 changes: 1 addition & 1 deletion modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2367,7 +2367,7 @@ def __setattr__(self, key, value):
# `__getattr__` will return the columns not present in `dir(self)`, so we do not need
# to manually track this state in the `dir`.
return
elif is_list_like(value):
elif is_list_like(value) and key not in ["index", "columns"]:
warnings.warn(
"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",
Expand Down
22 changes: 21 additions & 1 deletion modin/pandas/test/dataframe/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
import pandas
import matplotlib
import modin.pandas as pd
from modin.utils import to_pandas
from modin.utils import (
to_pandas,
get_current_execution,
)
from numpy.testing import assert_array_equal
import io
import warnings

from modin.pandas.test.utils import (
df_equals,
Expand Down Expand Up @@ -1171,3 +1175,19 @@ def test_hasattr_sparse(is_sparse_data):
else create_test_dfs(test_data["float_nan_data"])
)
eval_general(modin_df, pandas_df, lambda df: hasattr(df, "sparse"))


def test_setattr_axes():
# Test that setting .index or .columns does not warn
df = pd.DataFrame([[1, 2], [3, 4]])
with warnings.catch_warnings():
if get_current_execution() != "BaseOnPython":
mvashishtha marked this conversation as resolved.
Show resolved Hide resolved
# In BaseOnPython, setting columns raises a warning because get_axis
# defaults to pandas.
warnings.simplefilter("error")
df.index = ["foo", "bar"]
df.columns = [9, 10]

# Check that ensure_index was called
pandas.testing.assert_index_equal(df.index, pandas.Index(["foo", "bar"]))
pandas.testing.assert_index_equal(df.columns, pandas.Index([9, 10]))