-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Added RuntimeWarning to lib.fast_unique_multiple #33015
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
Added RuntimeWarning to lib.fast_unique_multiple #33015
Conversation
pandas/tests/test_lib.py
Outdated
@@ -39,6 +40,11 @@ def test_fast_unique_multiple_list_gen_sort(self): | |||
out = lib.fast_unique_multiple_list_gen(gen, sort=False) | |||
tm.assert_numpy_array_equal(np.array(out), expected) | |||
|
|||
def test_fast_unique_multiple_unsortable_runtimewarning(self): | |||
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000")], ["foo", "bar"]]) |
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.
can you target this test more specifically at the affected function? maybe pass np.array([Timestamp(...), "foo"])
?
It's not a rule/policy, but ideally the intra-pandas dependencies of test_lib would be limited to the dependencies of lib
.
Looks like at pandas/pandas/tests/indexes/multi/test_setops.py Lines 334 to 345 in 42ef409
@jbrockmendel Does having something like this: from pandas.compat.numpy import _is_numpy_dev
...
if _is_numpy_dev:
with tm.assert_produces_warning(RuntimeWarning):
result = idx.union(idx[:1])
else:
result = idx.union(idx[:1]) is the correct approach? |
Usually we would write
|
def test_fast_unique_multiple_unsortable_runtimewarning(self): | ||
arr = [np.array(["foo", pd.Timestamp("2000")])] | ||
with tm.assert_produces_warning(RuntimeWarning): | ||
lib.fast_unique_multiple(arr, sort=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.
Can you test this from an end user perspective?
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.
see above
pandas/_libs/lib.pyx
Outdated
@@ -286,7 +287,7 @@ def fast_unique_multiple(list arrays, sort: bool = True): | |||
try: | |||
uniques.sort() | |||
except TypeError: | |||
# TODO: RuntimeWarning? | |||
warnings.warn("The values in the array are unorderable", RuntimeWarning) |
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.
Can you indicate somethig about what to do about this? (eg passing the sort=False
keyword? I don't know if that is possible for all cases that may end up here)
Co-Authored-By: Joris Van den Bossche <[email protected]>
Everything else failed
@@ -332,12 +334,15 @@ def test_union_sort_other_empty_sort(slice_): | |||
tm.assert_index_equal(result, expected) | |||
|
|||
|
|||
@pytest.mark.xfail(reason="`warn` if statement is not working properly", strict=False) |
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 is this necesssary? non-strict xfails are among the patterns we want to avoid
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 is necessary because I couldn't get the CI to pass 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.
OK, lets troubleshoot that rather than xfail.
Why is there no expected warning on numpy-dev?
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 don't know, I have tried in d2cd2d9 to have:
warn = None if _is_numpy_dev else RuntimeWarning
We can trouble shoot from there.
So apparently I never needed the |
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.
lgtm. can you add a release note, can put in Other Enhancements for 1.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.
ping on green.
doc/source/whatsnew/v1.1.0.rst
Outdated
@@ -87,6 +87,7 @@ Other enhancements | |||
- Positional slicing on a :class:`IntervalIndex` now supports slices with ``step > 1`` (:issue:`31658`) | |||
- :class:`Series.str` now has a `fullmatch` method that matches a regular expression against the entire string in each row of the series, similar to `re.fullmatch` (:issue:`32806`). | |||
- :meth:`DataFrame.sample` will now also allow array-like and BitGenerator objects to be passed to ``random_state`` as seeds (:issue:`32503`) | |||
- :meth:`MultiIndex.union` will now raise `RuntimeWarning` if the object inside are unsortable, pass `sort=False` to suppress this 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.
can you add the issue number at the end (this PR number is fine if we don't have an issue)
ping @jreback |
thanks @MomIsBestFriend |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff