Skip to content

BUG: iloc setting columns not taking effect #33381

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

Closed
wants to merge 10 commits into from
11 changes: 10 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,16 @@ def _setitem_with_indexer(self, indexer, value):
(blk,) = self.obj._mgr.blocks
if 1 < blk.ndim: # in case of dict, keys are indices
val = list(value.values()) if isinstance(value, dict) else value
take_split_path = not blk._can_hold_element(val)

# https://github.com/pandas-dev/pandas/issues/33198
if (
isinstance(indexer, tuple)
and com.is_null_slice(indexer[0])
and self.ndim == len(indexer)
):
take_split_path = True
else:
take_split_path = not blk._can_hold_element(val)

# if we have any multi-indexes that have non-trivial slices
# (not null slices) then we must take the split path, xref
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/frame/indexing/test_iloc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np

import pandas as pd
import pandas._testing as tm


def test_unsure_about_the_name_and_location():
# https://github.com/pandas-dev/pandas/issues/33198
arr = np.random.randn(10 ** 6).reshape(500, 2000).astype(np.float64)
df = pd.DataFrame(arr)
df.iloc[:, 1000:] = df.iloc[:, 1000:].astype(np.float32)
expected = pd.Series(
{np.dtype("float32"): 1000, np.dtype("float64"): 1000}, dtype="int64"
)
result = df.dtypes.value_counts()
tm.assert_series_equal(result, expected)