Skip to content

ENH: Quantiles accepts an array #6955

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 1 commit into from
Apr 25, 2014

Conversation

TomAugspurger
Copy link
Contributor

Doesn't quite finish #4196, but it should be easy not that quantile takes arrays.

I did this on top of #6953, so that should go in first.

@@ -482,6 +482,8 @@ Enhancements
- Added ``how`` option to rolling-moment functions to dictate how to handle resampling; :func:``rolling_max`` defaults to max,
:func:``rolling_min`` defaults to min, and all others default to mean (:issue:`6297`)
- ``CustomBuisnessMonthBegin`` and ``CustomBusinessMonthEnd`` are now available (:issue:`6866`)
- :meth:`Series.quantile` and :meth:`DataFrame.quantile` now accept an array of
quantiles.
Copy link
Contributor

Choose a reason for hiding this comment

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

i think the last line has to be indented

@jreback jreback added this to the 0.14.0 milestone Apr 24, 2014
q : quantile, default 0.5 (50% quantile)
0 <= q <= 1
q : float or array-like, default 0.5 (50% quantile)
0 <= q <= 1, the quantile to compute
Copy link
Member

Choose a reason for hiding this comment

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

maybe quantile -> quantile(s)?

@TomAugspurger
Copy link
Contributor Author

Thanks, updated.

@@ -10945,6 +10945,16 @@ def test_quantile(self):
xp = df.median()
assert_series_equal(rs, xp)

def test_quantile_multi(self):
df = DataFrame(np.arange(1, 11).repeat(2).reshape(10, 2),
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe test with an empty frame too

@TomAugspurger TomAugspurger deleted the quantiles branch April 24, 2014 18:08
@TomAugspurger TomAugspurger reopened this Apr 24, 2014
@TomAugspurger
Copy link
Contributor Author

Added a test on empty frames

Also fixed a bug, I wasn't passing the axis argument correctly when quantiles was an array.

@TomAugspurger
Copy link
Contributor Author

One more thing, thinking ahead to fixing #4196; Are we ok with returning a FloatIndex? When you do df.describe() the quantiles are formatted as (e.g.) 50% instead of .50. I chose to use floats instead of formatting as strs since I see quantile being used in a pipeline, but describe is more useful as a final presentation thing.

@jreback
Copy link
Contributor

jreback commented Apr 24, 2014

for df,quantiles() a FloatIndex is just fine (that's what your example was). I agree describe is more pretty output

@TomAugspurger
Copy link
Contributor Author

OK. Good to merge?

@jreback
Copy link
Contributor

jreback commented Apr 24, 2014

can you add a test with datetimes both for Series and Frame for completeness?

@TomAugspurger
Copy link
Contributor Author

Do you mean with a DatetimeIndex or Datetime values? It doesn't look like we support quantile on datetime columns.

this is off master:

In [15]: df
Out[15]: 
           a  b
0 2010-01-01  1
1 2011-01-01  2
2 2012-01-01  3

[3 rows x 2 columns]

In [16]: df.quantile(.5)
Out[16]: 
b    2
dtype: float64

In [17]: df.set_index('a').quantile(.5)
Out[17]: 
b    2
dtype: float64

@jreback
Copy link
Contributor

jreback commented Apr 24, 2014

have to pass numeric_only=False

I think it will blow up actually
datetime64[ns] need a view('i8') (and not cast to float

@jreback
Copy link
Contributor

jreback commented Apr 24, 2014

iin docstring can you change ref from scipy.score..... to np.percentile (as tht is what it uses now)

@TomAugspurger
Copy link
Contributor Author

yeah it blows up pretty badly. My simple fix didn't work. Separate issue?

@jreback
Copy link
Contributor

jreback commented Apr 25, 2014

sure

TomAugspurger pushed a commit that referenced this pull request Apr 25, 2014
ENH: Quantiles accepts an array
@TomAugspurger TomAugspurger merged commit c6730ea into pandas-dev:master Apr 25, 2014
@TomAugspurger
Copy link
Contributor Author

OK. I'll make an issue for that. This PR doesn't officially close any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants