Skip to content

Commit bd561d9

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

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

pandas/core/internals.py

+12-9
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):
@@ -5172,15 +5175,15 @@ def is_uniform_join_units(join_units):
51725175
"""
51735176
return (
51745177
# all blocks need to have the same type
5175-
all([type(ju.block) is type(join_units[0].block) for ju in join_units]) # noqa
5178+
all([type(ju.block) is type(join_units[0].block) for ju in join_units]) and # noqa
51765179
# no blocks that would get missing values (can lead to type upcasts)
5177-
and all([not ju.is_na for ju in join_units])
5180+
all([not ju.is_na for ju in join_units]) and
51785181
# no blocks with indexers (as then the dimensions do not fit)
5179-
and all([not ju.indexers for ju in join_units])
5182+
all([not ju.indexers for ju in join_units]) and
51805183
# disregard Panels
5181-
and all([ju.block.ndim <= 2 for ju in join_units])
5184+
all([ju.block.ndim <= 2 for ju in join_units]) and
51825185
# only use this path when there is something to concatenate
5183-
and len(join_units) > 1)
5186+
len(join_units) > 1)
51845187

51855188

51865189
def get_empty_dtype_and_na(join_units):

pandas/core/reshape/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
_all_indexes_same)
1010
from pandas.core.categorical import (_factorize_from_iterable,
1111
_factorize_from_iterables)
12-
from pandas.core.internals import concatenate_block_managers, SparseBlock
12+
from pandas.core.internals import concatenate_block_managers
1313
from pandas.core import common as com
1414
from pandas.core.generic import NDFrame
1515
import pandas.core.dtypes.concat as _concat

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)