Skip to content

Performance regression in fillna #37833

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

Closed
3 tasks
TomAugspurger opened this issue Nov 14, 2020 · 6 comments · Fixed by #37945
Closed
3 tasks

Performance regression in fillna #37833

TomAugspurger opened this issue Nov 14, 2020 · 6 comments · Fixed by #37945
Labels
Performance Memory or execution speed performance Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@TomAugspurger
Copy link
Contributor

https://pandas.pydata.org/speed/pandas/index.html#replace.FillNa.time_fillna?python=3.8&Cython=0.29.21&p-inplace=False&commits=2eb353063d6bc4f2ed22e9943d26465e284b8393-68f53cd9e556698fe786aefe90466f233eb55841

2eb3530...68f53cd

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


@jorisvandenbossche jorisvandenbossche added this to the 1.2 milestone Nov 14, 2020
@jorisvandenbossche jorisvandenbossche added Performance Memory or execution speed performance Regression Functionality that used to work in a prior pandas version labels Nov 14, 2020
@jorisvandenbossche
Copy link
Member

cc @jbrockmendel

@jbrockmendel
Copy link
Member

im seeing a 19% slowdown vs 1.1.4, vs more than 2x on the link. can anyone else reproduce either of these measurements?

@jorisvandenbossche
Copy link
Member

So the snippet from the benchmark is basically:

N = 10 ** 6
rng = pd.date_range("1/1/2000", periods=N, freq="min")
data = np.random.randn(N)
data[::2] = np.nan
ts = pd.Series(data, index=rng)

%timeit ts.fillna(0.0)

Locally I see a 2x slowdown on master vs 1.1.

Comparing the snakeviz profiles, the additional times seems to come from _putmask_simpe

@jorisvandenbossche
Copy link
Member

I suppose the main difference is that np.putmask is actually faster as __setitem__ (with the data from example above):

In [6]: mask = np.isnan(data)

In [8]: %timeit np.putmask(data, mask, 0.0)
498 µs ± 43.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

In [9]: %timeit data[mask]= 0.0
2.43 ms ± 4.34 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

(now, I don't know if this difference scales with larger data)

@jbrockmendel
Copy link
Member

I suppose the main difference is that np.putmask is actually faster as setitem (with the data from example above):

Huh, good to know! ill make a PR to update putmask_simple and see if that solves the issue

@jbrockmendel
Copy link
Member

By updating putmask_simple I get this particular example to slightly faster than 1.1.4. WIll have to wait and see if the asv machine sees the same difference as i do locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Memory or execution speed performance Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants