Skip to content

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
merged 3 commits into from
May 2, 2023

Conversation

topper-123
Copy link
Contributor

10x improvement in this method (but small effect overall as this is typically a small part of total time cost).

@doc(ExtensionArray._empty)
def _empty(cls, shape: Shape, dtype: ExtensionDtype):
values = np.empty(shape, dtype=dtype.type)
values[:] = cls._internal_fill_value
Copy link
Member

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)

Copy link
Contributor Author

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 mroeschke added Performance Memory or execution speed performance NA - MaskedArrays Related to pd.NA and nullable extension arrays labels May 2, 2023
@mroeschke mroeschke added this to the 2.1 milestone May 2, 2023
@mroeschke mroeschke merged commit e49387d into pandas-dev:main May 2, 2023
@mroeschke
Copy link
Member

Thanks @topper-123

@topper-123 topper-123 deleted the perf_masked_array._empty branch May 2, 2023 21:02
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants