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 all 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 @@ -344,7 +345,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
33 changes: 0 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,6 @@
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -42,7 +41,6 @@
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -61,7 +59,6 @@
(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.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -142,7 +139,6 @@ def test_is_categorical_dtype(obj, expect):
(np.float64, True),
(np.complex128, True),
(np.str_, False),
(np.unicode_, False),
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -151,7 +147,6 @@ def test_is_categorical_dtype(obj, expect):
(np.float64(), True),
(np.complex128(), True),
(np.str_(), False),
(np.unicode_(), False),
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -170,7 +165,6 @@ 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.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -247,7 +241,6 @@ def test_is_numeric_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -256,7 +249,6 @@ def test_is_numeric_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -275,7 +267,6 @@ 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.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -352,7 +343,6 @@ def test_is_integer_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -361,7 +351,6 @@ def test_is_integer_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -380,7 +369,6 @@ 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.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -458,7 +446,6 @@ def test_is_integer(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, True),
(np.unicode_, True),
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -467,7 +454,6 @@ def test_is_integer(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), True),
(np.unicode_(), True),
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -486,7 +472,6 @@ 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.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
# (np.array([], dtype=object), False),
Expand Down Expand Up @@ -577,7 +562,6 @@ def test_is_string_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.datetime64, True),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -586,7 +570,6 @@ def test_is_string_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.datetime64(), True),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -605,7 +588,6 @@ 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.datetime64), True),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -682,7 +664,6 @@ def test_is_datetime_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -691,7 +672,6 @@ def test_is_datetime_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -710,7 +690,6 @@ 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.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -787,7 +766,6 @@ def test_is_list_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -796,7 +774,6 @@ def test_is_list_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -815,7 +792,6 @@ 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.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -895,7 +871,6 @@ def test_is_struct_dtype(obj, expect):
(np.float64, False),
(np.complex128, False),
(np.str_, False),
(np.unicode_, False),
(np.datetime64, False),
(np.timedelta64, False),
# NumPy scalars.
Expand All @@ -904,7 +879,6 @@ def test_is_struct_dtype(obj, expect):
(np.float64(), False),
(np.complex128(), False),
(np.str_(), False),
(np.unicode_(), False),
(np.datetime64(), False),
(np.timedelta64(), False),
# NumPy dtype objects.
Expand All @@ -923,7 +897,6 @@ 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.datetime64), False),
(np.array([], dtype=np.timedelta64), False),
(np.array([], dtype=object), False),
Expand Down Expand Up @@ -1004,7 +977,6 @@ def test_is_decimal_dtype(obj, expect):
np.float64,
np.complex128,
np.str_,
np.unicode_,
np.datetime64,
np.timedelta64,
# NumPy scalars.
Expand All @@ -1013,7 +985,6 @@ def test_is_decimal_dtype(obj, expect):
np.float64(),
np.complex128(),
np.str_(),
np.unicode_(),
np.datetime64(),
np.timedelta64(),
# NumPy dtype objects.
Expand All @@ -1032,7 +1003,6 @@ 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.datetime64),
np.array([], dtype=np.timedelta64),
np.array([], dtype=object),
Expand Down Expand Up @@ -1088,7 +1058,6 @@ def test_pandas_agreement(obj):
np.float64,
np.complex128,
np.str_,
np.unicode_,
np.datetime64,
np.timedelta64,
# NumPy scalars.
Expand All @@ -1097,7 +1066,6 @@ def test_pandas_agreement(obj):
np.float64(),
np.complex128(),
np.str_(),
np.unicode_(),
np.datetime64(),
np.timedelta64(),
# NumPy dtype objects.
Expand All @@ -1116,7 +1084,6 @@ 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.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