Closed Dr-Irv closed 6 years ago
Haven't thought about ops (comparisons or arithmetic) at all really. I think it's best to always call the EA's op, regardless of the argument type.
This should be sorted out when Period/DatetimeIndex are ported over, since those do support ops.
@TomAugspurger So is the port of Period/Datetimeindex on your "to-do" list? Is it intended for 0.23?
Yes, I think so (there's a dev chat tomorrow at 9:00 Eastern where we'll finalize these things, if you're able to attend).
On Wed, Apr 11, 2018 at 1:39 PM, Dr. Irv notifications@github.com wrote:
@TomAugspurger https://github.com/TomAugspurger So is the port of Period/Datetimeindex on your "to-do" list? Is it intended for 0.23?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pandas-dev/pandas/issues/20659#issuecomment-380554300, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQHItV7rO1dVllN0aoF_O32WP8oz_E1ks5tnk3WgaJpZM4TQgJt .
@TomAugspurger I could try to attend. Where do I find the details?
https://mail.python.org/pipermail/pandas-dev/2018-April/000738.html
From: Dr. Irv notifications@github.com Sent: Wednesday, April 11, 2018 2:18:43 PM To: pandas-dev/pandas Cc: Tom Augspurger; Mention Subject: Re: [pandas-dev/pandas] ExtensionArray support for comparisons to fundamental types and lists of those types (#20659)
@TomAugspurgerhttps://github.com/TomAugspurger I could try to attend. Where do I find the details?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/pandas-dev/pandas/issues/20659#issuecomment-380565915, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABQHIjUDDnbB-s_1PW3onm6UsDwv6ox5ks5tnlcTgaJpZM4TQgJt.
An initial attempt (which would be welcome to try out!), might be to add something in wrapper
similar as
elif is_categorical_dtype(self):
# Dispatch to Categorical implementation; pd.CategoricalIndex
# behavior is non-canonical GH#19513
res_values = dispatch_to_index_op(op, self, other, pd.Categorical)
return self._constructor(res_values, index=self.index,
name=res_name)
but then for extension arrays:
elif is_extension_array(self):
# Dispatch to ExtensionArray ops
res_values = dispatch_to_array_op(op, self, other)
return self._constructor(res_values, index=self.index,
name=res_name)
(but I am not very familiar with this part of the code)
@jorisvandenbossche that almost worked. What I needed was the is_extension_array_dtype
method. I'll submit a pull request soon.
Good to hear! (yeah, my code snippet was only quickly written, didn't check how the exact is_
check was spelled)
Closing because of #21261
This is probably for @TomAugspurger to look at.
I am trying out an idea that uses the new
ExtensionArray
capability that is in master. What I would like to do is override the relational operators__le__
,__ge__
, etc. I'm following the cyberpandas example that @TomAugspurger published.Using cyberpandas, I ran the following code
Code Sample, a copy-pastable example if possible
The result is the following output:
Problem description
The first exception is expected, because
cyberpandas.ip_array.__le__
raisesNotImplemented
, which is then caught inpandas.core.ops.na_op()
at line 1166.The second two exceptions are a bit not expected, because I would want the
IPArray.__le__()
method to be called so that theNotImplemented
exception is raised, but in this case, there is code inpandas.core.ops.wrapper()
around line 1248 that converts theSeries
into anumpy
array of objects, and thenpandas.core.ops._comp_method_OBJECT_ARRAY()
is called, which is trying to do an efficient comparison, which never calls theIPArray.__le__
method.So the problem here is that for my application, I would like the
ExtensionArray.__le__()
implementation to be called whenother
is either a constant or a list. I think the right fix is to place a test inwrapper
that says if theself.dtype
is an object, then callna_op()
directly.But maybe that's not the best way to do it??
Expected Output
exception raised for comparison to Series invalid type comparison exception raised for comparison to list invalid type comparison exception raised for comparison to int invalid type comparison no exception raised for comparison to IPType
Output of
pd.show_versions()