Skip to content

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

Merged
merged 24 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a8cbc37
Added RuntimeWarning to lib.fast_unique_multiple
Mar 25, 2020
28871d1
isort
Mar 25, 2020
3db5519
Fixed test case to be lib specific
Mar 25, 2020
8a7f6c9
Warning error message
Mar 25, 2020
9ce23ab
Not asserting the warning if on numpy_dev
Mar 25, 2020
d57aded
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Mar 26, 2020
1c3a45f
Troubleshoot failing test
Mar 26, 2020
9db8893
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Mar 26, 2020
ab8cc80
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Mar 26, 2020
d186e6d
Added information on how to suppress the warning
Mar 26, 2020
df301eb
Troubleshoot failing test
Mar 26, 2020
fde1e1a
Update pandas/_libs/lib.pyx
ShaharNaveh Mar 26, 2020
6d1508d
Marked failed test as xfail
Mar 26, 2020
1314e99
Marked xfailed-strict as False
Mar 27, 2020
f29760c
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Mar 27, 2020
e55bc81
Troubleshoot failing test
Mar 29, 2020
d2cd2d9
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Mar 29, 2020
b931025
Removed if statement related to numpy-dev
Mar 29, 2020
2c05ed2
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Mar 29, 2020
17a6f99
Added whatsnew
Mar 29, 2020
b7ace2b
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Mar 29, 2020
83e2e82
What's new refrence to this PR
Mar 31, 2020
564d416
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Mar 31, 2020
63a6104
Merge remote-tracking branch 'upstream/master' into TODO-runtimewarni…
Apr 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from fractions import Fraction
from numbers import Number

import sys
import warnings

import cython
from cython import Py_ssize_t
Expand Down Expand Up @@ -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)
Copy link
Member

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)

pass

return uniques
Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/indexes/multi/test_setops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import numpy as np
import pytest

from pandas.compat import PY37
from pandas.compat.numpy import _is_numpy_dev

import pandas as pd
from pandas import MultiIndex, Series
import pandas._testing as tm
Expand Down Expand Up @@ -337,7 +340,9 @@ def test_union_sort_other_incomparable():
idx = pd.MultiIndex.from_product([[1, pd.Timestamp("2000")], ["a", "b"]])

# default, sort=None
result = idx.union(idx[:1])
warn = None if (PY37 and _is_numpy_dev) else RuntimeWarning
with tm.assert_produces_warning(warn):
result = idx.union(idx[:1])
tm.assert_index_equal(result, idx)

# sort=False
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from pandas._libs import lib, writers as libwriters

import pandas as pd
from pandas import Index
import pandas._testing as tm

Expand Down Expand Up @@ -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):
arr = [np.array(["foo", pd.Timestamp("2000")])]
with tm.assert_produces_warning(RuntimeWarning):
lib.fast_unique_multiple(arr, sort=None)
Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

see above



class TestIndexing:
def test_maybe_indices_to_slice_left_edge(self):
Expand Down