Skip to content

TypeError: invalid type promotion #18212

Closed
@kdebrab

Description

@kdebrab

I'm not sure where to post this, as it involves pandas, seaborn, matplotlib and numpy.

As it works with pandas 0.20.3, but throws an error in pandas 0.21.0, it seems to be a pandas issue. Below, an easily reproducible example:

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')

Throws following error in pandas 0.21.0:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-a21ce0484562>", line 14, in <module>
    sns.stripplot(x='Datetime', y='Event / Element', hue='Element', data=df, orient='h')
  File "C:\Python27\lib\site-packages\seaborn\categorical.py", line 2603, in stripplot
    plotter.plot(ax, kwargs)
  File "C:\Python27\lib\site-packages\seaborn\categorical.py", line 1191, in plot
    self.draw_stripplot(ax, kws)
  File "C:\Python27\lib\site-packages\seaborn\categorical.py", line 1171, in draw_stripplot
    ax.scatter(strip_data, cat_pos, **kws)
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 1710, in inner
    return func(ax, *args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 4087, in scatter
    offsets = np.column_stack([x, y])
  File "C:\Python27\lib\site-packages\numpy\lib\shape_base.py", line 353, in column_stack
    return _nx.concatenate(arrays, 1)
TypeError: invalid type promotion

numpy==1.13.3
seaborn==0.8.1
matplotlib==2.1.0

The above code does work fine in pandas 0.20.3, with same versions of numpy, seaborn and matplotlib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions