-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: BaseMaskedArray._empty #53040
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
Merged
mroeschke
merged 3 commits into
pandas-dev:main
from
topper-123:perf_masked_array._empty
May 2, 2023
Merged
PERF: BaseMaskedArray._empty #53040
mroeschke
merged 3 commits into
pandas-dev:main
from
topper-123:perf_masked_array._empty
May 2, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mroeschke
reviewed
May 2, 2023
pandas/core/arrays/masked.py
Outdated
@doc(ExtensionArray._empty) | ||
def _empty(cls, shape: Shape, dtype: ExtensionDtype): | ||
values = np.empty(shape, dtype=dtype.type) | ||
values[:] = cls._internal_fill_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.fill
might be a bit faster
In [2]: values = np.empty(1_000_000, dtype=float)
In [3]: %timeit -n 1 -r 1 values[:] = np.nan
2.14 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
In [4]: %timeit -n 1 -r 1 values.fill(np.nan)
1.82 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I've updated.
mroeschke
approved these changes
May 2, 2023
Thanks @topper-123 |
1 task
topper-123
added a commit
to topper-123/pandas
that referenced
this pull request
May 7, 2023
* PERF: BaseMaskedArray._empty * update * use .fill method
Rylie-W
pushed a commit
to Rylie-W/pandas
that referenced
this pull request
May 19, 2023
* PERF: BaseMaskedArray._empty * update * use .fill method
Daquisu
pushed a commit
to Daquisu/pandas
that referenced
this pull request
Jul 8, 2023
* PERF: BaseMaskedArray._empty * update * use .fill method
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
NA - MaskedArrays
Related to pd.NA and nullable extension arrays
Performance
Memory or execution speed performance
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
10x improvement in this method (but small effect overall as this is typically a small part of total time cost).