diff --git a/pandas/core/internals/api.py b/pandas/core/internals/api.py index 2f8686fd38929..37e07af71213e 100644 --- a/pandas/core/internals/api.py +++ b/pandas/core/internals/api.py @@ -19,6 +19,7 @@ ) from pandas.core.arrays import DatetimeArray +from pandas.core.construction import extract_array from pandas.core.internals.blocks import ( Block, DatetimeTZBlock, @@ -49,7 +50,6 @@ def make_block( values, dtype = extract_pandas_array(values, dtype, ndim) - needs_reshape = False if klass is None: dtype = dtype or values.dtype klass = get_block_type(values, dtype) @@ -57,13 +57,14 @@ def make_block( elif klass is DatetimeTZBlock and not is_datetime64tz_dtype(values.dtype): # pyarrow calls get here values = DatetimeArray._simple_new(values, dtype=dtype) - needs_reshape = True if not isinstance(placement, BlockPlacement): placement = BlockPlacement(placement) ndim = maybe_infer_ndim(values, placement, ndim) - if needs_reshape: + if is_datetime64tz_dtype(values.dtype): + # GH#41168 ensure we can pass 1D dt64tz values + values = extract_array(values, extract_numpy=True) values = ensure_block_shape(values, ndim) check_ndim(values, placement, ndim) diff --git a/pandas/tests/internals/test_api.py b/pandas/tests/internals/test_api.py index 0062d5aa34319..21299d76eaf5a 100644 --- a/pandas/tests/internals/test_api.py +++ b/pandas/tests/internals/test_api.py @@ -3,6 +3,7 @@ in core.internals """ +import pandas as pd from pandas.core import internals from pandas.core.internals import api @@ -44,3 +45,12 @@ def test_namespace(): result = [x for x in dir(internals) if not x.startswith("__")] assert set(result) == set(expected + modules) + + +def test_make_block_2d_with_dti(): + # GH#41168 + dti = pd.date_range("2012", periods=3, tz="UTC") + blk = api.make_block(dti, placement=[0]) + + assert blk.shape == (1, 3) + assert blk.values.shape == (1, 3)