Skip to content

Commit c7c0135

Browse files
committed
TST: Add test for operations on DataFrame with Interval CategoricalIndex
1 parent 062dcb4 commit c7c0135

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

pandas/tests/frame/test_arithmetic.py

+15
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,18 @@ def test_arith_non_pandas_object(self):
642642
val3 = np.random.rand(*df.shape)
643643
added = pd.DataFrame(df.values + val3, index=df.index, columns=df.columns)
644644
tm.assert_frame_equal(df.add(val3), added)
645+
646+
def test_operations_with_interval_categories_index(self, all_arithmetic_operators):
647+
# GH#27415
648+
op = all_arithmetic_operators
649+
ind = pd.CategoricalIndex(pd.interval_range(start=0.0, end=2.0))
650+
651+
df = pd.DataFrame([[1, 2]], columns=ind)
652+
num = 100
653+
try:
654+
getattr(df, op)(num)
655+
except TypeError:
656+
pytest.fail(
657+
"Unexpected TypeError for operations on DataFrame\
658+
with interval categories as index"
659+
)

pandas/tests/indexing/test_categorical.py

-20
Original file line numberDiff line numberDiff line change
@@ -758,23 +758,3 @@ def test_map_with_dict_or_series(self):
758758
output = cur_index.map(mapper)
759759
# Order of categories in output can be different
760760
tm.assert_index_equal(expected, output)
761-
762-
def test_operations_with_interval_categories_index(self):
763-
ind = pd.CategoricalIndex(pd.interval_range(start=0.0, end=2.0))
764-
df = pd.DataFrame([[1, 2]], columns=ind)
765-
# __add__
766-
result = df + 100
767-
expected = pd.DataFrame([[101, 102]], columns=ind)
768-
tm.assert_frame_equal(result, expected)
769-
# __substract__
770-
result = df - 100
771-
expected = pd.DataFrame([[-99, -98]], columns=ind)
772-
tm.assert_frame_equal(result, expected)
773-
# __multiply__
774-
result = df * 100
775-
expected = pd.DataFrame([[100, 200]], columns=ind)
776-
tm.assert_frame_equal(result, expected)
777-
# __divide__
778-
result = df / 100
779-
expected = pd.DataFrame([[0.01, 0.02]], columns=ind)
780-
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)