Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pandas/core/internals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -49,21 +50,21 @@ 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)

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)
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/internals/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
in core.internals
"""

import pandas as pd
from pandas.core import internals
from pandas.core.internals import api

Expand Down Expand Up @@ -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)