Skip to content

TypeError: invalid type promotion with datetime coordinate #1325

@kdebrab

Description

@kdebrab

With pandas 0.21.0, the following fails (whereas it works fine with pandas 0.20.3):

import pandas as pd
import seaborn as sns

index = pd.date_range('2017-06-01', periods=16)
df = pd.DataFrame(index=index, columns=['a', 'b', 'c'])
df.iloc[:2, 0] = '1000'
df.iloc[[2, 3, 6, 8, 10, 12, 14, 15], 1] = '1000'
df.iloc[[4, 5, 9, 13], 2] = '1000'
df.iloc[[7, 11], 1] = '1001'
df.index.name = 'Datetime'
df.columns.name = 'Element'
df = df.stack().rename('Event').reset_index()
df['Event / Element'] = df['Event'] + ' / ' + df['Element']
sns.stripplot(x='Datetime', y='Event / Element', hue='Element', data=df, orient='h')

The reason is that pandas no longer registers the matplotlib converter for datetimes on import.

The fix is to explicitly register the converters before plotting:

from pandas.tseries import converter
converter.register()

The same fix has been implemented in xarray for a similar issue: pydata/xarray#1661.

I reported this to pandas as pandas-dev/pandas#18212.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions