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

Performance regression in DataFrame[bool_indexer] #33924

Closed
TomAugspurger opened this issue May 1, 2020 · 1 comment · Fixed by #34199
Closed

Performance regression in DataFrame[bool_indexer] #33924

TomAugspurger opened this issue May 1, 2020 · 1 comment · Fixed by #34199
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Performance Memory or execution speed performance Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@TomAugspurger
Copy link
Contributor

import numpy as np
import pandas as pd

idx_dupe = np.array(range(30)) * 99
df = pd.DataFrame(np.random.randn(10000, 5))
bool_indexer = [True] * 5000 + [False] * 5000


%timeit df[np.array(bool_indexer)]
# 1.0.2
2.58 ms ± 108 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

# master
5.47 ms ± 192 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

Note that this only affects the case where the indexer is a list. Performance looks fine when an ndarray is passed.

https://pandas.pydata.org/speed/pandas/index.html#indexing.DataFrameNumericIndexing.time_bool_indexer?commits=80d37adcc3d9bfbbe17e8aa626d6b5873465ca98-4f89c261f624305fc7bae6c43ae862663994be34 points to somewhere in 80d37ad..4f89c26, which has a bunch of commits.

@TomAugspurger TomAugspurger added Indexing Related to indexing on series/frames, not to indexes themselves Performance Memory or execution speed performance Needs Triage Issue that has not been reviewed by a pandas team member labels May 1, 2020
@TomAugspurger TomAugspurger added this to the 1.1 milestone May 1, 2020
@TomAugspurger TomAugspurger added the Regression Functionality that used to work in a prior pandas version label May 1, 2020
@rohitkg98
Copy link
Contributor

The performance issue seems to be in

def check_array_indexer(array: AnyArrayLike, indexer: Any) -> Any:

in which

is called which calls infer_dtype twice.
It seems to have started from this PR #31150.
The performance also seems to have worsened just a tiny bit after this commit.
I have used cProfile to perform the analysis. I apologise for any mistakes, I'm still a novice dev.

@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label May 11, 2020
jreback pushed a commit that referenced this issue Jun 1, 2020
#34199)

* PERF: Remove unnecessary  copies in sorting functions

* PERF: Create array from list with given dtype=bool

* Run black

* Run tests

* Run tests

* Run tests

* Fix imports

* Add asv

* Run black

* Remove asv

* Add requested changes

* Run black

* Delete newline

* Fix whatsnew

* Add requested changes

* Fix

* Fix

* Fix typo

* Fix

* Update asv

Co-authored-by: mproszewska <magdalena.proszewska@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves 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