diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 15cee1419afb5..203a0c675282d 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -883,9 +883,8 @@ def series_generator(self): # of it. Kids: don't do this at home. ser = self.obj._ixs(0, axis=0) mgr = ser._mgr - blk = mgr.blocks[0] - if is_extension_array_dtype(blk.dtype): + if is_extension_array_dtype(ser.dtype): # values will be incorrect for this block # TODO(EA2D): special case would be unnecessary with 2D EAs obj = self.obj @@ -896,7 +895,7 @@ def series_generator(self): for (arr, name) in zip(values, self.index): # GH#35462 re-pin mgr in case setitem changed it ser._mgr = mgr - blk.values = arr + mgr.set_values(arr) ser.name = name yield ser diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index e013a7f680d6f..2ad7471d6f086 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1646,6 +1646,15 @@ def fast_xs(self, loc): """ raise NotImplementedError("Use series._values[loc] instead") + def set_values(self, values: ArrayLike): + """ + Set the values of the single block in place. + + Use at your own risk! This does not check if the passed values are + valid for the current Block/SingleBlockManager (length, dtype, etc). + """ + self.blocks[0].values = values + # -------------------------------------------------------------------- # Constructor Helpers