Skip to content

Commit

Permalink
BUG: Cannot use categorical IntervalIndex as index when creating pivo…
Browse files Browse the repository at this point in the history
…t_table (pandas-dev#25814)
  • Loading branch information
peterpanmj committed Jun 10, 2019
1 parent 0f3e8e8 commit c242a8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Expand Up @@ -181,7 +181,7 @@ def contains(cat, key, container):
# can't be in container either.
try:
loc = cat.categories.get_loc(key)
except KeyError:
except (KeyError, TypeError):
return False

# loc is the location of key in categories, but also the *value*
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/reshape/test_pivot.py
Expand Up @@ -198,6 +198,17 @@ def test_pivot_with_non_observable_dropna(self, dropna):

tm.assert_frame_equal(result, expected)

def test_pivot_with_interval_index(self, dropna):
df = pd.DataFrame(
{'A': pd.Categorical([pd.Interval(0, 1)] * 4),
'B': [1] * 4})
result = df.pivot_table(index='A', values='B', dropna=dropna)
expected = pd.DataFrame(
{'B': [1]},
index=pd.Index(pd.Categorical([pd.Interval(0, 1)]),
name='A'))
tm.assert_frame_equal(result, expected)

def test_pass_array(self):
result = self.data.pivot_table(
'D', index=self.data.A, columns=self.data.C)
Expand Down

0 comments on commit c242a8e

Please sign in to comment.