Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.19.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ Bug Fixes

- Bug in ``SeriesGroupBy.transform`` with datetime values and missing groups (:issue:`13191`)
- Bug where empty ``Series`` were incorrectly coerced in datetime-like numeric operations (:issue:`13844`)

- Bug in ``Categorical`` constructor when passed a ``Categorical`` containing datetimes with timezones (:issue:`14190`)
- Bug in ``Series.str.extractall()`` with ``str`` index raises ``ValueError`` (:issue:`13156`)
- Bug in ``Series.str.extractall()`` with single group and quantifier (:issue:`13382`)
- Bug in ``DatetimeIndex`` and ``Period`` subtraction raises ``ValueError`` or ``AttributeError`` rather than ``TypeError`` (:issue:`13078`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def __init__(self, values, categories=None, ordered=False,
ordered = values.ordered
if categories is None:
categories = values.categories
values = values.__array__()
values = values.get_values()

elif isinstance(values, (ABCIndexClass, ABCSeries)):
pass
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,21 @@ def test_constructor_from_index_series_period(self):
result = pd.Categorical(pd.Series(idx))
tm.assert_index_equal(result.categories, idx)

def test_constructor_invariant(self):
# GH 14190
vals = [
np.array([1., 1.2, 1.8]),
np.array([1, 2, 3], dtype='int64'),
['a', 'b', 'c'],
pd.period_range('2014-01-01', '2014-01-05'),
pd.date_range('2014-01-01', '2014-01-05'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might throw some NaT and nans in

pd.date_range('2014-01-01', '2014-01-05', tz='US/Eastern')
]
for val in vals:
c = Categorical(val)
c2 = Categorical(c)
tm.assert_categorical_equal(c, c2)

def test_from_codes(self):

# too few categories
Expand Down