Skip to content

Commit e5b8208

Browse files
committed
Add tz_convert test
1 parent 42395cb commit e5b8208

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pandas/core/indexes/accessors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def __new__(cls, data):
322322
orig = data if is_categorical_dtype(data) else None
323323
if orig is not None:
324324
data = Series(
325-
orig.values.__array__(),
325+
np.asarray(orig.values),
326326
name=orig.name,
327327
copy=False,
328328
dtype=orig.values.categories.dtype,

pandas/tests/indexes/test_category.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,18 @@ def test_dt_tz_localize(self, tz_aware_fixture):
11351135
expected = datetimes.dt.tz_localize(tz)
11361136
tm.assert_series_equal(result, expected)
11371137

1138-
@pytest.mark.parametrize("accessor", [("year"), ("month"), ("day")])
1138+
def test_dt_tz_convert(self, tz_aware_fixture):
1139+
# GH 27952
1140+
tz = tz_aware_fixture
1141+
datetimes = pd.Series(
1142+
["2019-01-01", "2019-01-01", "2019-01-02"], dtype="datetime64[ns, MET]"
1143+
)
1144+
categorical = datetimes.astype("category")
1145+
result = categorical.dt.tz_convert(tz)
1146+
expected = datetimes.dt.tz_convert(tz)
1147+
tm.assert_series_equal(result, expected)
1148+
1149+
@pytest.mark.parametrize("accessor", ["year", "month", "day"])
11391150
def test_dt_other_accessors(self, accessor):
11401151
# GH 27952
11411152
datetimes = pd.Series(

0 commit comments

Comments
 (0)