Repository: pandas-dev/pandas

Issue:
KeyError on master in TestExcelWrtiter
https://travis-ci.org/pandas-dev/pandas/jobs/424485100 isn't master, but it's seeminglyon other PRs. e.g. https://travis-ci.org/pandas-dev/pandas/jobs/424480841#L2253

```
______________ TestExcelWriter.test_tsframe[openpyxl-.xlsx-True] _______________
[gw0] darwin -- Python 3.5.6 /Users/travis/miniconda3/envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestExcelWriter object at 0x1148ad9b0>
merge_cells = True, engine = 'openpyxl', ext = '.xlsx'
    def test_tsframe(self, merge_cells, engine, ext):
        df = tm.makeTimeDataFrame()[:5]
    
>       df.to_excel(self.path, 'test1')
pandas/tests/io/test_excel.py:1153: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pandas/core/frame.py:1749: in to_excel
    engine=engine)
pandas/io/formats/excel.py:658: in write
    freeze_panes=freeze_panes)
pandas/io/excel.py:1419: in write_cells
    xcell.value, fmt = self._value_with_fmt(cell.val)
../../../miniconda3/envs/pandas/lib/python3.5/site-packages/openpyxl/cell/cell.py:291: in value
    self._bind_value(value)
../../../miniconda3/envs/pandas/lib/python3.5/site-packages/openpyxl/cell/cell.py:193: in _bind_value
    self._set_time_format(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <Cell 'test1'.A2>, value = Timestamp('2000-01-03 00:00:00', freq='B')
    def _set_time_format(self, value):
        """Set number format for Python date or time"""
        fmts = {
            datetime.datetime:numbers.FORMAT_DATE_DATETIME,
            datetime.date:numbers.FORMAT_DATE_YYYYMMDD2,
            datetime.time:numbers.FORMAT_DATE_TIME6,
            datetime.timedelta:numbers.FORMAT_DATE_TIMEDELTA,
                }
>       self.number_format = fmts[type(value)]
E       KeyError: <class 'pandas._libs.tslibs.timestamps.Timestamp'>
```

Trying to reproduce locally now.


Discussion:
Breaking change from `2.5.5` to `2.5.6` on `openpyxl`:

`2.5.5`:

https://bitbucket.org/openpyxl/openpyxl/src/c0235e89c62962df89df12946bff07f33aa971a7/openpyxl/cell/cell.py?at=2.5.5&fileviewer=file-view-default#cell.py-268

`2.5.6`:

https://bitbucket.org/openpyxl/openpyxl/src/260d5b0b9caf7c648d86f39bb524e18e55c48d72/openpyxl/cell/cell.py?at=2.5.6&fileviewer=file-view-default#cell.py-269

Breaking commits:

https://bitbucket.org/openpyxl/openpyxl/commits/9b0dbd6c043ad64e7d32fe833dc25fd55433fd7d
https://bitbucket.org/openpyxl/openpyxl/commits/076d1dacd88926f28af6c9abc1b3813add0a138e

We need to fix `openpyxl` at `2.5.5` for now.
FYI, someone has just filed an issue on Bitbucket:

https://bitbucket.org/openpyxl/openpyxl/issues/1094/error-with-pandas-datetimeindex

Resolving patch:
diff --git a/scripts/convert_deps.py b/scripts/convert_deps.py
--- a/scripts/convert_deps.py
+++ b/scripts/convert_deps.py
@@ -1,6 +1,7 @@
 """
 Convert the conda environment.yaml to a pip requirements.txt
 """
+import re
 import yaml
 
 exclude = {'python=3'}
@@ -15,6 +16,7 @@
 required = dev['dependencies']
 required = [rename.get(dep, dep) for dep in required if dep not in exclude]
 optional = [rename.get(dep, dep) for dep in optional if dep not in exclude]
+optional = [re.sub("(?<=[^<>])=", '==', dep) for dep in optional]
 
 
 with open("ci/requirements_dev.txt", 'wt') as f:


Test patch: