Repository: pandas-dev/pandas
Pull request: TST: Add test for operations on DataFrame with Interval CategoricalIndex
- [x] closes #27415
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Problem statement:
Using a `CategoricalIndex` with interval categories as column index breaks operations on a `DataFrame`
#### Code Sample, a copy-pastable example if possible

```python
>>> a = pd.DataFrame([[1, 2]], columns=pd.CategoricalIndex(pd.interval_range(start=0.0, end=2.0)))
>>> a.T * 100

              0
(0.0, 1.0]  100
(1.0, 2.0]  200

>>> a * 100

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-166-9b495e0b7c52> in <module>()
----> 1 a * 100

~/anaconda3/envs/python3/lib/python3.6/site-packages/pandas/core/ops.py in f(self, other, axis, level, fill_value)
   2034 
   2035             assert np.ndim(other) == 0
-> 2036             return self._combine_const(other, op)
   2037 
   2038     f.__name__ = op_name

...

TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'
```

#### Problem description

When the columns index is a `CategoricalIndex` with interval categories, basic operations like multiplication by a scalar are broken.

The minimal example is a contrived case, but the situation can arise in common data analysis workflows:
1) Use `pd.cut` to bin floating point values
2) Perform a `pivot_table` operation with the binned values as columns

For instance:
```python
df = pd.DataFrame({'values': [10.0, 21.0, 32.0, 43.0], 
                   'strings': ['A', 'B', 'C', 'D']})
df['intervals'] = pd.cut(df['values'], [0, 20, 40, 60])
p = df.pivot_table(index='strings', columns='intervals', values='values', aggfunc='sum')
```

A DataFrame with a column index of this kind is brokwn in other ways, for example it does not display as an HTML table in a Jupyter notebook, etc.


#### Expected Output

              
```
    (0.0, 1.0] (1.0, 2.0] 
0  100          200
```

#### Workaround

`df.columns = df.columns.categories` seems to make the DataFrame behave correctly.

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.123-86.109.amzn1.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: 3.5.1
pip: 10.0.1
setuptools: 39.1.0
Cython: 0.28.4
numpy: 1.15.4
scipy: 1.1.0
pyarrow: 0.14.0
xarray: None
IPython: 6.4.0
sphinx: 1.7.4
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.5
feather: None
matplotlib: 3.0.3
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.4
lxml.etree: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.11
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: 0.1.5
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
</details>

Hints from issue discussion:
This looks to be fixed on 0.25.0:
```python
In [1]: import pandas as pd; pd.__version__
Out[1]: '0.25.0rc0'

In [2]: a = pd.DataFrame([[1, 2]], columns=pd.CategoricalIndex(pd.interval_range(start=0.0, end=2.0)))

In [3]: a * 100
Out[3]: 
   (0.0, 1.0]  (1.0, 2.0]
0         100         200
```

Not sure exactly which PR fixed this, but I don't recall this exact issue coming up before, so could probably use some tests to ensure that there's not a regression.
I will add the test for this.

Commit message: Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	doc/source/whatsnew/v0.25.0.rst
#	pandas/core/arrays/categorical.py
#	pandas/tests/arrays/categorical/test_operators.py

Patch to review:

Code review comments:
diff_hunk: @@ -642,3 +642,18 @@ def test_arith_non_pandas_object(self):
         val3 = np.random.rand(*df.shape)
         added = pd.DataFrame(df.values + val3, index=df.index, columns=df.columns)
         tm.assert_frame_equal(df.add(val3), added)
+
+    def test_operations_with_interval_categories_index(self, all_arithmetic_operators):
+        # GH#27415
+        op = all_arithmetic_operators
+        ind = pd.CategoricalIndex(pd.interval_range(start=0.0, end=2.0))
+
+        df = pd.DataFrame([[1, 2]], columns=ind)
+        num = 100
+        try:
+            getattr(df, op)(num)
path: pandas/tests/frame/test_arithmetic.py
text: @user1:
these need to compare the result, if there is an exception it will *already* be raised so we don't need to specifically fail.

your code should look like

```
result = getattr(df, op((num)
expected = 
tm.assert_frame_equal(result, expected)
```