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

PERF/CLN: restrict _isna_ndarraylike to actual ndarray/EA #40254

Merged

Conversation

jorisvandenbossche
Copy link
Member

xref #39146

I am looking at some isna related benchmarks, and noticing a lot of overhead related to checking of types. This makes _isna_ndarraylike stricter to only handle ndarray and EA, and not Series/Index (and therefore also renamed it to _isna_array).

Reproducer from the frame_methods.py::Isnull benchmark:

N = 10 ** 3
sample = np.array([np.nan, 1.0])
data = np.random.choice(sample, (N, N))
df = DataFrame(data)
df_am = df._as_manager("array")
In [3]: %timeit df_am.isna()
5.03 ms ± 125 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  <-- master
4.25 ms ± 9.94 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  <-- PR

This gives a small improvement. But it further allows to directly use _is_array instead of the general isna from Manager.isna, which will give further improvements (but was planning to do this as a follow-up)

@jorisvandenbossche jorisvandenbossche added Clean Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Performance Memory or execution speed performance labels Mar 5, 2021
@jreback jreback added this to the 1.3 milestone Mar 5, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jbrockmendel
Copy link
Member

LGTM pending green

@jorisvandenbossche jorisvandenbossche merged commit d17476d into pandas-dev:master Mar 5, 2021
@jorisvandenbossche jorisvandenbossche deleted the am-perf-isna branch March 5, 2021 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants