pandas: BUG: iloc setting columns not taking effect

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)

>>> df.dtypes.value_counts()
float64    2000
dtype: int64

I would expect 1000 float64 columns and 1000 float32 columns. I get the expected behavior if I set a single column before trying to set all 1000:

df = pd.DataFrame(arr)
df[1000] = df[1000].astype(np.float32)
df.iloc[:, 1000:] = df.iloc[:, 1000:].astype(np.float32)

>>> df.dtypes.value_counts()
float32    1000
float64    1000
dtype: int64

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 34 (34 by maintainers)

Most upvoted comments

seems to not break anything (passed pandas/tests/frame/methods/**/*),

I’ll be pretty surprised if that passes the full test suite, but give it a try