-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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: support EAs in nargsort without warning #25595
BUG: support EAs in nargsort without warning #25595
Conversation
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.
Probably want a whatsnew?
@@ -239,7 +241,9 @@ def nargsort(items, kind='quicksort', ascending=True, na_position='last'): | |||
""" | |||
|
|||
# specially handle Categorical |
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.
This comment is slightly stale now.
@@ -239,7 +241,9 @@ def nargsort(items, kind='quicksort', ascending=True, na_position='last'): | |||
""" | |||
|
|||
# specially handle Categorical | |||
if is_categorical_dtype(items): | |||
if is_extension_array_dtype(items): | |||
if isinstance(items, ABCIndexClass): |
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.
Hmm, so when we have ExtensionArrays-backed indexes in the future, this is liable to break? Or we'll need a ._values
as part of the interface...
I don't suppose items = items._values_for_argsort
works here? In theory, DatetimeArray could just use i8 values for sorting, bypassing the warning?
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.
._values
is defined to be "the best array representation", so if the Index is backed by an EA, it will always return the EA? (also if we have an ExtensionIndex). I can maybe also use the public .array
now?
I don't suppose items = items._values_for_argsort
No, because we want to dispatch to the argsort
method of the EA, I think?
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.
Sorry, I mis-remembered where the warning was coming from (I thought it was implemented on DatetimeArray).
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.
why exactly is this change needed? should this not just defer to the index .argsort
, which for DTA handles this?
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.
The Index.argsort
has a different signature (and that's not specific to DatetimeTZ, but the general Index.argsort, so I would rather not deal with that here. Can open an issue for that)
There is no behaviour change, just the warning, so thought it might not be needed. But can certainly add one. |
|
||
def test_nargsort_datetimearray_warning(self, recwarn): | ||
# https://github.com/pandas-dev/pandas/issues/25439 | ||
# can be removed once the FutureWarning for np.array(DTA) is removed |
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.
is there a reason you are not using tm.assert_produces_warning
, this looks non-standard
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.
Because I want to assert that a specific warning is not raised. I found it a bit clunky as well, so if you know a better way, all ears.
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.
with pytest.raises(None):
is the cleanest, but I think our linter disallows that.
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.
Assuming you mean pytest.warns(None)
: in that case you still have to do something like
with pytest.warns(None) as record:
....
assert len(record) == 0
giving basically the same as I did above (but above I did it with the recwarn fixture instead of the with statement. Happy to use the with statement if that is more typically used / easier to understand. Actually now thinking about it, I would find that clearer myself :-))
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.
Yes, I meant pytest.warns
. I really thought that pytest.warns(None)
asserted that there were no warnings, but apparently not.
In theory, you could rely on our global "fail on warning" setting from the one CI job, but I don't think I trust that enough :)
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.
tm.assert_produces_warning(None)
already does this
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.
But not for a specific warning, what I tried to do here.
But OK, maybe it is not that important to do it (the reason I wanted to do that was to avoid unrelated failures, eg when numpy starts raising a warning on something unrelated used under the hood).
Will change to tm.assert_produces_warning(None)
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.
But not for a specific warning, what I tried to do here.
But OK, maybe it is not that important to do it (the reason I wanted to do that was to avoid unrelated failures, eg when numpy starts raising a warning on something unrelated used under the hood).
sure, but try to guard against unexpected warnings is a bit of a rabbit hole
@@ -239,7 +241,9 @@ def nargsort(items, kind='quicksort', ascending=True, na_position='last'): | |||
""" | |||
|
|||
# specially handle Categorical | |||
if is_categorical_dtype(items): | |||
if is_extension_array_dtype(items): | |||
if isinstance(items, ABCIndexClass): |
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.
why exactly is this change needed? should this not just defer to the index .argsort
, which for DTA handles this?
There is actually a broader issue here (also the reason that the tests are failing, eg IntervalArray.argsort is failing on data with NaNs): the Eg
so in the above, If we want to generalize this, this "sorting last" should be moved inside Unless we would add the |
@TomAugspurger would you be fine with catching this specific warning in our code for 0.24.2 (because my explanation above has too much impact for 0.24.2)? |
Yeah, as a short-term fix that's fine.
…On Sun, Mar 10, 2019 at 9:18 AM Joris Van den Bossche < ***@***.***> wrote:
@TomAugspurger <https://github.com/TomAugspurger> would you be fine with
catching this specific warning in our code for 0.24.2 (because my
explanation above has too much impact for 0.24.2)?
Or what is the reason for objecting filtering the warning? It's certainly
not good practice, but showing this warning is just plain confusing for
users, as there is nothing they should do anything about.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#25595 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIpfXQ3q-Jp8eEi3fI-md_00m2C-hks5vVRQ7gaJpZM4bjnoX>
.
|
OK, opened #25629 for that |
can you merge master |
superseded by #26354 |
Closes #25439