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

BUG: PandasArray._quantile when empty #46110

Merged
merged 4 commits into from
Feb 26, 2022

Conversation

jbrockmendel
Copy link
Member

Not user-facing, but still good to have fixed.

Gets rid of our last non-idiomatic usage of _from_factorized, xref #33276

return np.array([na_value] * len(qs), dtype=values.dtype)
# Can't pass dtype=values.dtype here bc we might have na_value=np.nan
# with values.dtype=int64 see test_quantile_empty
return np.array([na_value] * len(qs))
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this would kill anything else here but na_value * np.empty((len(qs), )) should be significantly faster.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that would break things when na_value is e.g. -1

Copy link
Member

Choose a reason for hiding this comment

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

Good point. np.zeros should work?

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe you mean np.full? regardless id prefer not to bikeshed here

Copy link
Member

Choose a reason for hiding this comment

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

What we could also use is

np.tile(np.array([na_value]), (len(qs, ))

This should also be faster than the list multiplication

%timeit np.array([na_value] * 1_000_000)
53.6 ms ± 1.71 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%timeit na_value * np.zeros((1_000_000, ))
1.3 ms ± 28.4 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
%timeit np.tile(np.array([na_value]), (1_000_000, ))
2.75 ms ± 84.5 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

Copy link
Member

Choose a reason for hiding this comment

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

maybe you mean np.full? regardless id prefer not to bikeshed here

Ok with me, just wanted to mention it

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to use np.full, green

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

Are there tests for period/datetime/timedelta already?

@jbrockmendel
Copy link
Member Author

Yes

@rhshadrach
Copy link
Member

Not seeing any tests for quantile in arrays, am I missing it, or might they be somewhere else?

@jbrockmendel
Copy link
Member Author

Tested indirectly in the dataframe/series tests

@jbrockmendel
Copy link
Member Author

gentle ping; a couple of follow-ups in the works

@jreback jreback added this to the 1.5 milestone Feb 26, 2022
@jreback jreback added Bug ExtensionArray Extending pandas with custom dtypes or arrays. labels Feb 26, 2022
@jreback jreback merged commit 3f52f4e into pandas-dev:main Feb 26, 2022
@jreback
Copy link
Contributor

jreback commented Feb 26, 2022

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants