Skip to content

Commit 4f3acf1

Browse files
authored
BUG: make_block with dt64tz-1d #41168 (#41202)
1 parent 48c5224 commit 4f3acf1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pandas/core/internals/api.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020

2121
from pandas.core.arrays import DatetimeArray
22+
from pandas.core.construction import extract_array
2223
from pandas.core.internals.blocks import (
2324
Block,
2425
DatetimeTZBlock,
@@ -49,21 +50,21 @@ def make_block(
4950

5051
values, dtype = extract_pandas_array(values, dtype, ndim)
5152

52-
needs_reshape = False
5353
if klass is None:
5454
dtype = dtype or values.dtype
5555
klass = get_block_type(values, dtype)
5656

5757
elif klass is DatetimeTZBlock and not is_datetime64tz_dtype(values.dtype):
5858
# pyarrow calls get here
5959
values = DatetimeArray._simple_new(values, dtype=dtype)
60-
needs_reshape = True
6160

6261
if not isinstance(placement, BlockPlacement):
6362
placement = BlockPlacement(placement)
6463

6564
ndim = maybe_infer_ndim(values, placement, ndim)
66-
if needs_reshape:
65+
if is_datetime64tz_dtype(values.dtype):
66+
# GH#41168 ensure we can pass 1D dt64tz values
67+
values = extract_array(values, extract_numpy=True)
6768
values = ensure_block_shape(values, ndim)
6869

6970
check_ndim(values, placement, ndim)

pandas/tests/internals/test_api.py

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
in core.internals
44
"""
55

6+
import pandas as pd
67
from pandas.core import internals
78
from pandas.core.internals import api
89

@@ -44,3 +45,12 @@ def test_namespace():
4445

4546
result = [x for x in dir(internals) if not x.startswith("__")]
4647
assert set(result) == set(expected + modules)
48+
49+
50+
def test_make_block_2d_with_dti():
51+
# GH#41168
52+
dti = pd.date_range("2012", periods=3, tz="UTC")
53+
blk = api.make_block(dti, placement=[0])
54+
55+
assert blk.shape == (1, 3)
56+
assert blk.values.shape == (1, 3)

0 commit comments

Comments
 (0)