Skip to content

Commit ab3f3a2

Browse files
fix categorical and datetimetz (when in dataframe + converted to object)
1 parent 1c35aca commit ab3f3a2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pandas/core/internals.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -2421,13 +2421,15 @@ def concat_same_type(self, to_concat, placement=None):
24212421
Concatenate list of single blocks of the same type.
24222422
"""
24232423
to_concat = [blk.values for blk in to_concat]
2424-
values = _concat._concat_categorical(to_concat)
2424+
values = _concat._concat_categorical(to_concat, axis=self.ndim - 1)
24252425

24262426
if is_categorical_dtype(values.dtype):
24272427
return self.make_block_same_class(
24282428
values, placement=placement or slice(0, len(values), 1))
24292429
else:
2430-
return make_block(values, placement=placement or slice(0, len(values), 1))
2430+
return make_block(
2431+
values, placement=placement or slice(0, len(values), 1),
2432+
ndim=self.ndim)
24312433

24322434

24332435
class DatetimeBlock(DatetimeLikeBlockMixin, Block):
@@ -2711,13 +2713,14 @@ def concat_same_type(self, to_concat, placement=None):
27112713
Concatenate list of single blocks of the same type.
27122714
"""
27132715
to_concat = [blk.values for blk in to_concat]
2714-
values = _concat._concat_datetime(to_concat)
2716+
values = _concat._concat_datetime(to_concat, axis=self.ndim - 1)
27152717

27162718
if is_datetimetz(values):
27172719
return self.make_block_same_class(
27182720
values, placement=placement or slice(0, len(values), 1))
27192721
else:
2720-
return make_block(values, placement=placement or slice(0, len(values), 1))
2722+
return make_block(
2723+
values, placement=placement or slice(0, len(values), 1))
27212724

27222725

27232726
class SparseBlock(NonConsolidatableMixIn, Block):

pandas/tests/internals/test_external_block.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import numpy as np
55

66
import pandas as pd
7-
from pandas.core.internals import Block, BlockManager, SingleBlockManager, NonConsolidatableMixIn
7+
from pandas.core.internals import (
8+
Block, BlockManager, SingleBlockManager, NonConsolidatableMixIn)
89

910

1011
class CustomBlock(NonConsolidatableMixIn, Block):

0 commit comments

Comments
 (0)