Skip to content
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

Minor fixups for future NumPy 2 compatibility #15590

Merged
merged 6 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def contains(

Returning an Index of booleans using only a literal pattern.

>>> data = ['Mouse', 'dog', 'house and parrot', '23.0', np.NaN]
>>> data = ['Mouse', 'dog', 'house and parrot', '23.0', np.nan]
>>> idx = cudf.Index(data)
>>> idx
Index(['Mouse', 'dog', 'house and parrot', '23.0', None], dtype='object')
Expand Down
12 changes: 6 additions & 6 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ def isna(self):
>>> import cudf
>>> import numpy as np
>>> import pandas as pd
>>> df = cudf.DataFrame({'age': [5, 6, np.NaN],
>>> df = cudf.DataFrame({'age': [5, 6, np.nan],
... 'born': [pd.NaT, pd.Timestamp('1939-05-27'),
... pd.Timestamp('1940-04-25')],
... 'name': ['Alfred', 'Batman', ''],
Expand All @@ -1095,7 +1095,7 @@ def isna(self):

Show which entries in a Series are NA.

>>> ser = cudf.Series([5, 6, np.NaN, np.inf, -np.inf])
>>> ser = cudf.Series([5, 6, np.nan, np.inf, -np.inf])
>>> ser
0 5.0
1 6.0
Expand All @@ -1113,7 +1113,7 @@ def isna(self):

Show which entries in an Index are NA.

>>> idx = cudf.Index([1, 2, None, np.NaN, 0.32, np.inf])
>>> idx = cudf.Index([1, 2, None, np.nan, 0.32, np.inf])
>>> idx
Index([1.0, 2.0, <NA>, <NA>, 0.32, Inf], dtype='float64')
>>> idx.isna()
Expand Down Expand Up @@ -1156,7 +1156,7 @@ def notna(self):
>>> import cudf
>>> import numpy as np
>>> import pandas as pd
>>> df = cudf.DataFrame({'age': [5, 6, np.NaN],
>>> df = cudf.DataFrame({'age': [5, 6, np.nan],
... 'born': [pd.NaT, pd.Timestamp('1939-05-27'),
... pd.Timestamp('1940-04-25')],
... 'name': ['Alfred', 'Batman', ''],
Expand All @@ -1174,7 +1174,7 @@ def notna(self):

Show which entries in a Series are NA.

>>> ser = cudf.Series([5, 6, np.NaN, np.inf, -np.inf])
>>> ser = cudf.Series([5, 6, np.nan, np.inf, -np.inf])
>>> ser
0 5.0
1 6.0
Expand All @@ -1192,7 +1192,7 @@ def notna(self):

Show which entries in an Index are NA.

>>> idx = cudf.Index([1, 2, None, np.NaN, 0.32, np.inf])
>>> idx = cudf.Index([1, 2, None, np.nan, 0.32, np.inf])
>>> idx
Index([1.0, 2.0, <NA>, <NA>, 0.32, Inf], dtype='float64')
>>> idx.notna()
Expand Down
6 changes: 5 additions & 1 deletion python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from cudf.core.single_column_frame import SingleColumnFrame
from cudf.utils.docutils import copy_docstring
from cudf.utils.dtypes import (
_NUMPY_SCTYPES,
_maybe_convert_to_default_type,
find_common_type,
is_mixed_with_object_dtype,
Expand Down Expand Up @@ -341,7 +342,10 @@ def _data(self):
@_cudf_nvtx_annotate
def __contains__(self, item):
if isinstance(item, bool) or not isinstance(
item, tuple(np.sctypes["int"] + np.sctypes["float"] + [int, float])
item,
tuple(
_NUMPY_SCTYPES["int"] + _NUMPY_SCTYPES["float"] + [int, float]
),
):
return False
try:
Expand Down
66 changes: 33 additions & 33 deletions python/cudf/cudf/tests/test_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.str_, False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -42,7 +42,7 @@
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.str_(), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -61,7 +61,7 @@
(np.array([], dtype=np.float64), False),
(np.array([], dtype=np.complex128), False),
(np.array([], dtype=np.str_), False),
(np.array([], dtype=np.unicode_), False),
(np.array([], dtype=np.str_), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_is_categorical_dtype(obj, expect):
(np.float64, True),
(np.complex128, True),
(np.str_, False),
(np.unicode_, False),
(np.str_, False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -151,7 +151,7 @@ def test_is_categorical_dtype(obj, expect):
(np.float64(), True),
(np.complex128(), True),
(np.str_(), False),
(np.unicode_(), False),
(np.str_(), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -170,7 +170,7 @@ def test_is_categorical_dtype(obj, expect):
(np.array([], dtype=np.float64), True),
(np.array([], dtype=np.complex128), True),
(np.array([], dtype=np.str_), False),
(np.array([], dtype=np.unicode_), False),
(np.array([], dtype=np.str_), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -247,7 +247,7 @@ def test_is_numeric_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.str_, False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -256,7 +256,7 @@ def test_is_numeric_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.str_(), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -275,7 +275,7 @@ def test_is_numeric_dtype(obj, expect):
(np.array([], dtype=np.float64), False),
(np.array([], dtype=np.complex128), False),
(np.array([], dtype=np.str_), False),
(np.array([], dtype=np.unicode_), False),
(np.array([], dtype=np.str_), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_is_integer_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.str_, False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -361,7 +361,7 @@ def test_is_integer_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.str_(), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -380,7 +380,7 @@ def test_is_integer_dtype(obj, expect):
(np.array([], dtype=np.float64), False),
(np.array([], dtype=np.complex128), False),
(np.array([], dtype=np.str_), False),
(np.array([], dtype=np.unicode_), False),
(np.array([], dtype=np.str_), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -458,7 +458,7 @@ def test_is_integer(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, True),
(np.unicode_, True),
(np.str_, True),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -467,7 +467,7 @@ def test_is_integer(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), True),
(np.unicode_(), True),
(np.str_(), True),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -486,7 +486,7 @@ def test_is_integer(obj, expect):
(np.array([], dtype=np.float64), False),
(np.array([], dtype=np.complex128), False),
(np.array([], dtype=np.str_), True),
(np.array([], dtype=np.unicode_), True),
(np.array([], dtype=np.str_), True),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
# (np.array([], dtype=object), False),
Expand Down Expand Up @@ -577,7 +577,7 @@ def test_is_string_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.str_, False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, True),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -586,7 +586,7 @@ def test_is_string_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.str_(), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), True),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -605,7 +605,7 @@ def test_is_string_dtype(obj, expect):
(np.array([], dtype=np.float64), False),
(np.array([], dtype=np.complex128), False),
(np.array([], dtype=np.str_), False),
(np.array([], dtype=np.unicode_), False),
(np.array([], dtype=np.str_), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), True),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -682,7 +682,7 @@ def test_is_datetime_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.str_, False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -691,7 +691,7 @@ def test_is_datetime_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.str_(), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -710,7 +710,7 @@ def test_is_datetime_dtype(obj, expect):
(np.array([], dtype=np.float64), False),
(np.array([], dtype=np.complex128), False),
(np.array([], dtype=np.str_), False),
(np.array([], dtype=np.unicode_), False),
(np.array([], dtype=np.str_), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -787,7 +787,7 @@ def test_is_list_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.str_, False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -796,7 +796,7 @@ def test_is_list_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.str_(), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -815,7 +815,7 @@ def test_is_list_dtype(obj, expect):
(np.array([], dtype=np.float64), False),
(np.array([], dtype=np.complex128), False),
(np.array([], dtype=np.str_), False),
(np.array([], dtype=np.unicode_), False),
(np.array([], dtype=np.str_), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -895,7 +895,7 @@ def test_is_struct_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.str_, False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -904,7 +904,7 @@ def test_is_struct_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.str_(), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -923,7 +923,7 @@ def test_is_struct_dtype(obj, expect):
(np.array([], dtype=np.float64), False),
(np.array([], dtype=np.complex128), False),
(np.array([], dtype=np.str_), False),
(np.array([], dtype=np.unicode_), False),
(np.array([], dtype=np.str_), False),
seberg marked this conversation as resolved.
Show resolved Hide resolved
(np.array([], dtype=np.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -1004,7 +1004,7 @@ def test_is_decimal_dtype(obj, expect):
np.float64,
np.complex128,
np.str_,
np.unicode_,
np.str_,
seberg marked this conversation as resolved.
Show resolved Hide resolved
np.datetime64,
np.timedelta64,
# NumPy scalars.
Expand All @@ -1013,7 +1013,7 @@ def test_is_decimal_dtype(obj, expect):
np.float64(),
np.complex128(),
np.str_(),
np.unicode_(),
np.str_(),
seberg marked this conversation as resolved.
Show resolved Hide resolved
np.datetime64(),
np.timedelta64(),
# NumPy dtype objects.
Expand All @@ -1032,7 +1032,7 @@ def test_is_decimal_dtype(obj, expect):
np.array([], dtype=np.float64),
np.array([], dtype=np.complex128),
np.array([], dtype=np.str_),
np.array([], dtype=np.unicode_),
np.array([], dtype=np.str_),
seberg marked this conversation as resolved.
Show resolved Hide resolved
np.array([], dtype=np.datetime64),
np.array([], dtype=np.timedelta64),
np.array([], dtype=object),
Expand Down Expand Up @@ -1088,7 +1088,7 @@ def test_pandas_agreement(obj):
np.float64,
np.complex128,
np.str_,
np.unicode_,
np.str_,
seberg marked this conversation as resolved.
Show resolved Hide resolved
np.datetime64,
np.timedelta64,
# NumPy scalars.
Expand All @@ -1097,7 +1097,7 @@ def test_pandas_agreement(obj):
np.float64(),
np.complex128(),
np.str_(),
np.unicode_(),
np.str_(),
seberg marked this conversation as resolved.
Show resolved Hide resolved
np.datetime64(),
np.timedelta64(),
# NumPy dtype objects.
Expand All @@ -1116,7 +1116,7 @@ def test_pandas_agreement(obj):
np.array([], dtype=np.float64),
np.array([], dtype=np.complex128),
np.array([], dtype=np.str_),
np.array([], dtype=np.unicode_),
np.array([], dtype=np.str_),
seberg marked this conversation as resolved.
Show resolved Hide resolved
np.array([], dtype=np.datetime64),
np.array([], dtype=np.timedelta64),
np.array([], dtype=object),
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_categorical_dataframe_slice_copy():
pd.Series(["1.0", "2.5", "3.001", None, "9"], dtype="category"),
pd.Series(["a", "b", "c", "c", "b", "a", "b", "b"]),
pd.Series(["aa", "b", "c", "c", "bb", "bb", "a", "b", "b"]),
pd.Series([1, 2, 3, 89, None, np.nan, np.NaN], dtype="float64"),
pd.Series([1, 2, 3, 89, None, np.nan, np.nan], dtype="float64"),
pd.Series([1, 2, 3, 89], dtype="float64"),
pd.Series([1, 2.5, 3.001, 89], dtype="float64"),
pd.Series([None, None, None]),
Expand Down Expand Up @@ -493,7 +493,7 @@ def test_categorical_typecast(data, cat_type):
pd.Series([1, 2, 3, 89]),
pd.Series(["a", "b", "c", "c", "b", "a", "b", "b"]),
pd.Series(["aa", "b", "c", "c", "bb", "bb", "a", "b", "b"]),
pd.Series([1, 2, 3, 89, None, np.nan, np.NaN], dtype="float64"),
pd.Series([1, 2, 3, 89, None, np.nan, np.nan], dtype="float64"),
pd.Series([1, 2, 3, 89], dtype="float64"),
pd.Series([1, 2.5, 3.001, 89], dtype="float64"),
pd.Series([None, None, None]),
Expand Down
Loading
Loading