Python Forum
Data dtype error according to the rule "safe"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data dtype error according to the rule "safe"
Hello everyone,

I am trying to plot a regression from the Seaborn library in Pycharm, and unfortunately I stumble upon an error which I feel may be due to my system (I am on a Windows 10, 64-bit OS). The part of my code that causes the issue is as follows:

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

path = ""
df = pd.read_csv(path)

width = 12
height = 10
plt.figure(figsize=(width, height))
sns.regplot(x="highway-mpg", y="price", data=df)
TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'
This error also appears if I try to use the lmplot function
sns.lmplot(x="highway-mpg", y="price", data=df)
Other Seaborn functions that I have tried work properly.

Any help would be much appreciated!
I just run your code without any problem seaborn v. 0.9.0, pandas v.0.25.1.
Thanks for the reply. I guess it's a system / pycharm error, but I just can't figure it out :(
(Feb-05-2020, 08:19 AM)AndreasMavro Wrote: Thanks for the reply. I guess it's a system / pycharm error, but I just can't figure it out :(

Were you able to resolve this issue ? I am facing the same.
@chedge, unfortunately still not. I ended up running my regressions on Spyder.
A work around by JohanC is available here:

It requires editing Line 84 of Seaborn's file.

Possibly Related Threads…
Thread Author Replies Views Last Post
  FutureWarning: Logical ops (and, or, xor) between Pandas objects and dtype-less seque NewBiee 5 1,351 Sep-12-2023, 03:15 PM
Last Post: deanhystad
  dtype in not working in mad() function ift38375 8 3,718 Jul-22-2019, 02:53 AM
Last Post: scidam
  ValueError: Input contains infinity or a value too large for dtype('float64') Rabah_r 1 12,797 Apr-06-2019, 11:08 AM
Last Post: scidam
  numpy dtype anomaly bluefrog 4 3,415 Nov-07-2018, 12:37 AM
Last Post: bluefrog
  interp2d casting ruled not 'safe' sebseb 0 1,793 Jul-05-2018, 09:21 AM
Last Post: sebseb

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020