TypeError: invalid type promotion
See original GitHub issueI’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.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
`TypeError: invalid type promotion` when appending to a ...
Now in order to concatenate lineitem to Ticket_data , it must first be implicitly cast from nested lists to an array. Since you...
Read more >ColumnTransformer give "TypeError: invalid type promotion"
The error occurs when exactly n - 1 columns are transformed (where n is the total number of columns) and the one column...
Read more >Pandas : numpy.where: TypeError: invalid type promotion
Pandas : numpy.where: TypeError : invalid type promotion [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] Pandas ...
Read more >Invalid Type Promotion error in numpy expression-Pandas ...
Keras classifier error "ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float)." How avoid error "TypeError: invalid data...
Read more >numpy.promote_types — NumPy v1.8 Manual - omz:software
Returns the data type with the smallest size and smallest scalar kind to ... First data type. ... line 1, in <module> TypeError:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey, coming across this issue in 1.0.0 Since tseries no longer has a
converter
I tried to usefrom pandas.plotting._matplotlib import converter
converter.register()
But I’m still getting invalid type promotion. Using a dataframe with a DateTimeIndex and 2 columns of floats.
https://github.com/pydata/xarray/pull/1669/files provides a hint to the solution/workaround.
First execute:
and then execute above example and everything works fine in pandas==0.21.0.