Skip to content

Commit

Permalink
FIX-#4720: Fix incorrect warning when setting frame.columns or frame …
Browse files Browse the repository at this point in the history
…index (#4721)

Signed-off-by: Brock <jbrockmendel@gmail.com>
  • Loading branch information
jbrockmendel authored Jul 27, 2022
1 parent cfafbb2 commit 23c40a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
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":
# 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]))

0 comments on commit 23c40a6

Please sign in to comment.