Skip to content

Commit

Permalink
fix categorical and datetimetz (when in dataframe + converted to object)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Oct 6, 2017
1 parent 1c35aca commit ab3f3a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2421,13 +2421,15 @@ def concat_same_type(self, to_concat, placement=None):
Concatenate list of single blocks of the same type.
"""
to_concat = [blk.values for blk in to_concat]
values = _concat._concat_categorical(to_concat)
values = _concat._concat_categorical(to_concat, axis=self.ndim - 1)

if is_categorical_dtype(values.dtype):
return self.make_block_same_class(
values, placement=placement or slice(0, len(values), 1))
else:
return make_block(values, placement=placement or slice(0, len(values), 1))
return make_block(
values, placement=placement or slice(0, len(values), 1),
ndim=self.ndim)


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

if is_datetimetz(values):
return self.make_block_same_class(
values, placement=placement or slice(0, len(values), 1))
else:
return make_block(values, placement=placement or slice(0, len(values), 1))
return make_block(
values, placement=placement or slice(0, len(values), 1))


class SparseBlock(NonConsolidatableMixIn, Block):
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/internals/test_external_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np

import pandas as pd
from pandas.core.internals import Block, BlockManager, SingleBlockManager, NonConsolidatableMixIn
from pandas.core.internals import (
Block, BlockManager, SingleBlockManager, NonConsolidatableMixIn)


class CustomBlock(NonConsolidatableMixIn, Block):
Expand Down

0 comments on commit ab3f3a2

Please sign in to comment.