diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index b74399ed86fbd..20dcc7c3dce5f 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -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 diff --git a/pandas/tests/frame/indexing/test_iloc.py b/pandas/tests/frame/indexing/test_iloc.py new file mode 100644 index 0000000000000..a29ab65554701 --- /dev/null +++ b/pandas/tests/frame/indexing/test_iloc.py @@ -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)