Skip to content

Commit 109e3d0

Browse files
jorisvandenbosscheadrien pacifico
authored andcommitted
Restore test_categorical.py to commit 6537afe
1 parent 3255910 commit 109e3d0

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

pandas/tests/reshape/concat/test_categorical.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pandas as pd
88
from pandas import (
99
Categorical,
10-
CategoricalIndex,
1110
DataFrame,
1211
Series,
1312
)
@@ -76,13 +75,13 @@ def test_concat_categoricalindex(self):
7675
# GH 16111, categories that aren't lexsorted
7776
categories = [9, 0, 1, 2, 3]
7877

79-
a = Series(1, index=CategoricalIndex([9, 0], categories=categories))
80-
b = Series(2, index=CategoricalIndex([0, 1], categories=categories))
81-
c = Series(3, index=CategoricalIndex([1, 2], categories=categories))
78+
a = Series(1, index=pd.CategoricalIndex([9, 0], categories=categories))
79+
b = Series(2, index=pd.CategoricalIndex([0, 1], categories=categories))
80+
c = Series(3, index=pd.CategoricalIndex([1, 2], categories=categories))
8281

8382
result = pd.concat([a, b, c], axis=1)
8483

85-
exp_idx = CategoricalIndex([9, 0, 1, 2], categories=categories)
84+
exp_idx = pd.CategoricalIndex([9, 0, 1, 2], categories=categories)
8685
exp = DataFrame(
8786
{
8887
0: [1, 1, np.nan, np.nan],
@@ -100,7 +99,7 @@ def test_categorical_concat_preserve(self):
10099
s = Series(list("abc"), dtype="category")
101100
s2 = Series(list("abd"), dtype="category")
102101

103-
exp = Series(list("abcabd"), dtype="category")
102+
exp = Series(list("abcabd"))
104103
res = pd.concat([s, s2], ignore_index=True)
105104
tm.assert_series_equal(res, exp)
106105

@@ -148,8 +147,8 @@ def test_categorical_index_preserver(self):
148147
result = pd.concat([df2, df3])
149148
expected = pd.concat(
150149
[
151-
df2.set_axis(df2.index.astype("category"), axis=0),
152-
df3.set_axis(df3.index.astype("category"), axis=0),
150+
df2.set_axis(df2.index.astype(object), axis=0),
151+
df3.set_axis(df3.index.astype(object), axis=0),
153152
]
154153
)
155154
tm.assert_frame_equal(result, expected)
@@ -180,8 +179,7 @@ def test_concat_categorical_datetime(self):
180179

181180
result = pd.concat([df1, df2])
182181
expected = DataFrame(
183-
{"x": Series([datetime(2021, 1, 1), datetime(2021, 1, 2)])},
184-
dtype="category",
182+
{"x": Series([datetime(2021, 1, 1), datetime(2021, 1, 2)])}
185183
)
186184

187185
tm.assert_equal(result, expected)
@@ -229,17 +227,15 @@ def test_categorical_index_upcast(self):
229227
b = DataFrame({"foo": [4, 3]}, index=Categorical(["baz", "bar"]))
230228

231229
res = pd.concat([a, b])
232-
exp = DataFrame(
233-
{"foo": [1, 2, 4, 3]}, index=Categorical(["foo", "bar", "baz", "bar"])
234-
)
230+
exp = DataFrame({"foo": [1, 2, 4, 3]}, index=["foo", "bar", "baz", "bar"])
235231

236232
tm.assert_equal(res, exp)
237233

238234
a = Series([1, 2], index=Categorical(["foo", "bar"]))
239235
b = Series([4, 3], index=Categorical(["baz", "bar"]))
240236

241237
res = pd.concat([a, b])
242-
exp = Series([1, 2, 4, 3], index=Categorical(["foo", "bar", "baz", "bar"]))
238+
exp = Series([1, 2, 4, 3], index=["foo", "bar", "baz", "bar"])
243239

244240
tm.assert_equal(res, exp)
245241

@@ -261,9 +257,9 @@ def test_categorical_missing_from_one_frame(self):
261257
def test_concat_categorical_same_categories_different_order(self):
262258
# https://github.com/pandas-dev/pandas/issues/24845
263259

264-
c1 = CategoricalIndex(["a", "a"], categories=["a", "b"], ordered=False)
265-
c2 = CategoricalIndex(["b", "b"], categories=["b", "a"], ordered=False)
266-
c3 = CategoricalIndex(
260+
c1 = pd.CategoricalIndex(["a", "a"], categories=["a", "b"], ordered=False)
261+
c2 = pd.CategoricalIndex(["b", "b"], categories=["b", "a"], ordered=False)
262+
c3 = pd.CategoricalIndex(
267263
["a", "a", "b", "b"], categories=["a", "b"], ordered=False
268264
)
269265

0 commit comments

Comments
 (0)