Skip to content

Commit a4f6e89

Browse files
put conversion to ndarray in make_block
1 parent fcd29ed commit a4f6e89

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

pandas/core/frame.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3620,11 +3620,6 @@ def reindexer(value):
36203620
value = cast_scalar_to_array(len(self.index), value)
36213621
value = maybe_cast_to_datetime(value, infer_dtype)
36223622

3623-
# convert pandas array to numpy array
3624-
if isinstance(value, ABCPandasArray):
3625-
value = value.to_numpy()
3626-
return np.atleast_2d(np.asarray(value))
3627-
36283623
# return internal types directly
36293624
if is_extension_type(value) or is_extension_array_dtype(value):
36303625
return value

pandas/core/internals/blocks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,8 @@ def make_block(values, placement, klass=None, ndim=None, dtype=None,
30353035
# For now, blocks should be backed by ndarrays when possible.
30363036
if isinstance(values, ABCPandasArray):
30373037
values = values.to_numpy()
3038+
if ndim and ndim > 1:
3039+
values = np.atleast_2d(values)
30383040

30393041
if isinstance(dtype, PandasDtype):
30403042
dtype = dtype.numpy_dtype

pandas/tests/internals/test_internals.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
SparseArray)
1818
import pandas.core.algorithms as algos
1919
from pandas.core.arrays import DatetimeArray, TimedeltaArray
20-
from pandas.core.internals import BlockManager, SingleBlockManager, make_block
20+
from pandas.core.internals import (
21+
BlockManager, ObjectBlock, SingleBlockManager, make_block)
2122
import pandas.util.testing as tm
2223
from pandas.util.testing import (
2324
assert_almost_equal, assert_frame_equal, assert_series_equal, randn)
@@ -1318,4 +1319,6 @@ def test_add_column_with_pandas_array():
13181319
df['c'] = pd.array([1, 2, None, 3])
13191320
df2 = pd.DataFrame({'a': [1, 2, 3, 4], 'b': ['a', 'b', 'c', 'd'],
13201321
'c': pd.array([1, 2, None, 3])})
1322+
assert(df2['c']._data.blocks[0].__class__ == ObjectBlock)
1323+
assert(df['c']._data.blocks[0].__class__ == ObjectBlock)
13211324
assert_frame_equal(df, df2)

0 commit comments

Comments
 (0)