Skip to content
Prev Previous commit
Next Next commit
add dropped columns to warning message
  • Loading branch information
jbrockmendel committed Aug 9, 2021
commit 083d21bb77bb2ff497bb5dbc9a743d722d9dba55
4 changes: 3 additions & 1 deletion pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,12 @@ def hfunc2d(values: ArrayLike) -> ArrayLike:

if 0 != len(new_mgr.items) != len(mgr.items):
# GH#42738 ignore_failures dropped nuisance columns
dropped = mgr.items.difference(new_mgr.items)
warnings.warn(
"Dropping of nuisance columns in rolling operations "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you list the columns that are problematic in the error message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated + green

"is deprecated; in a future version this will raise TypeError. "
"Select only valid columns before calling the operation.",
"Select only valid columns before calling the operation. "
f"Dropped columns were {dropped}",
FutureWarning,
stacklevel=find_stack_level(),
)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/window/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def tests_skip_nuisance():
def test_skip_sum_object_raises():
df = DataFrame({"A": range(5), "B": range(5, 10), "C": "foo"})
r = df.rolling(window=3)
with tm.assert_produces_warning(FutureWarning, match="nuisance columns"):
msg = r"nuisance columns.*Dropped columns were Index\(\['C'\], dtype='object'\)"
with tm.assert_produces_warning(FutureWarning, match=msg):
# GH#42738
result = r.sum()
expected = DataFrame(
Expand Down