-
Notifications
You must be signed in to change notification settings - Fork 590
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
support for passing multiple quantiles in .quantile() #1094
Conversation
|
@cpcloud currently failing like: |
ibis/expr/operations.py
Outdated
| class MultiQuantile(Reduction): | ||
|
|
||
| input_type = [value, | ||
| rules.collection(name='quantile'), |
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.
You want rules.array(dt.double) here (dt.double for now, we'll extend as needed).
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.
collection here means "column or table". I think for now we want to be very strict about the inputs and we can expand support for different concrete inputs (like Series) as needed.
ibis/pandas/execution.py
Outdated
| ) | ||
| def execute_series_quantile_with_interpolation( | ||
| op, data, quantile, scope=None): | ||
| return data.quantile(q=quantile, interpolation=op.interpolation) | ||
|
|
||
|
|
||
| @execute_node.register( | ||
| ops.MultiQuantile, pd.Series, ir.ValueList, |
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.
ValueList will need to be list.
ibis/pandas/tests/test_operations.py
Outdated
| tm.assert_series_equal(result, expected) | ||
| result = ibis_func(t.float64_with_zeros).execute() | ||
| expected = pandas_func(df.float64_with_zeros) | ||
| tm.assert_series_equal(result, expected) |
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.
We'll return a list here since this is a reduction to a single array-scalar so assert is probably good enough.
ibis/expr/api.py
Outdated
| op = _ops.Quantile(arg, quantile, interpolation) | ||
| try: | ||
| op = _ops.Quantile(arg, quantile, interpolation) | ||
| except _com.IbisTypeError: |
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.
I know I originally suggested this, but I'm not actually sure whether IbisTypeError can be thrown for any other reason here than quantile being the wrong type.
Probably better to just check isinstance(quantile, collections.Sequence). I think it's more readable that way, and expresses the type checking intent more clearly.
ibis/expr/api.py
Outdated
| @@ -1043,7 +1043,7 @@ def quantile(arg, quantile, interpolation='linear'): | |||
|
|
|||
| Parameters | |||
| ---------- | |||
| quantile : float, default 0.5 (50% quantile) | |||
| quantile : float or array-like, default 0.5 (50% quantile) | |||
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.
Should remove the 0.5 since we're not going to default to anything here.
ibis/pandas/execution.py
Outdated
| @@ -180,13 +180,21 @@ def execute_series_clip(op, data, lower, upper, scope=None): | |||
|
|
|||
|
|
|||
| @execute_node.register( | |||
| ops.Quantile, pd.Series, float, | |||
| ops.Quantile, pd.Series, float | |||
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.
You should be able to just do (float, list) here so you don't have to duplicate anything.
|
@jreback regarding the failure, try adding |
|
ok, after inferring, getting this: |
|
@jreback rebase and try on top of master |
ibis/expr/api.py
Outdated
| """ | ||
| op = _ops.Quantile(arg, quantile, interpolation) | ||
| if isinstance(quantile, collections.Sequence): | ||
| quantile = infer_literal_type(quantile) |
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.
You just need to remove this line and your tests pass.
|
pushed, should be all green. now returning a list for MultiQuantile. side issue. test_operations.py getting big, maybe should split to multiple files. |
|
@cpcloud green. |
ibis/expr/operations.py
Outdated
| @@ -720,6 +720,17 @@ class Quantile(Reduction): | |||
| output_type = rules.type_of_arg(1) | |||
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.
So, I think this needs to be:
def output_type(self):
first_arg = self.args[0]
first_arg_type = first_arg.type()
if isinstance(first_arg_type, dt.Integer):
result_type = dt.double
else:
result_type = first_arg_type
return result_type.scalar_type()because the result will be a double if the input is an integer and it will take on the type of the first argument otherwise.
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.
Also I think the number(name='quantile') should be double(name='quantile') since we only allow doubles there.
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.
updated, though no test on the output (IIRC we are not actually checking via ibis anywhere, only as a test result).
Also I think the number(name='quantile') should be double(name='quantile')
we allow float & int input. (e.g. 0 and 1 are valid).
|
@jreback Yeah, |
specify output type as double if integer input
|
thanks @jreback |
xref #1090