Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pandas slow replace with int64 columns in dataframe #28084

Closed
apiszcz opened this issue Aug 22, 2019 · 1 comment · Fixed by #28099
Closed

pandas slow replace with int64 columns in dataframe #28084

apiszcz opened this issue Aug 22, 2019 · 1 comment · Fixed by #28099

Comments

@apiszcz
Copy link

apiszcz commented Aug 22, 2019

Reproduced issue in part without n2 and n3 and with n2 n3 see prior issue:
#12257

The replace runs 10x slower when encountering int64 columns

WITHOUT n2,n3, 1.73 seconds

a1=np.zeros((40000000,1))
a1[:,:]=np.inf
df=pd.DataFrame(a1)
df['a1']=''
df['n1']=0.0
# df['n2']=0.0
# df['n2']=df['n2'].astype(np.int64)
# df['n3']=0.0
# df['n3']=df['n3'].astype(np.int64)
df['n1'].astype('datetime64[ns]')
df['a1']=df['a1'].astype('category')
%time df.replace([np.inf, -np.inf], np.nan)

WITH n2, n3 21.4 seconds

a1=np.zeros((40000000,1))
a1[:,:]=np.inf
df=pd.DataFrame(a1)
df['a1']=''
df['n1']=0.0
df['n2']=0.0
df['n2']=df['n2'].astype(np.int64)
df['n3']=0.0
df['n3']=df['n3'].astype(np.int64)
df['n1'].astype('datetime64[ns]')
df['a1']=df['a1'].astype('category')
%time df.replace([np.inf, -np.inf], np.nan)
@jbrockmendel
Copy link
Member

Looks like in core.internals.blocks.replace there is a path form handling isinstance(to_replace, list) that could be optimized significantly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants