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

Fix return type of Index.isna & Index.notna #11769

Merged
merged 2 commits into from
Sep 26, 2022
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
28 changes: 14 additions & 14 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ def _copy_type_metadata(
return self

@_cudf_nvtx_annotate
def isnull(self):
def isna(self):
"""
Identify missing values.

Expand Down Expand Up @@ -1236,7 +1236,7 @@ def isnull(self):
0 5 <NA> Alfred <NA>
1 6 1939-05-27 00:00:00.000000 Batman Batmobile
2 <NA> 1940-04-25 00:00:00.000000 Joker
>>> df.isnull()
>>> df.isna()
age born name toy
0 False True False True
1 False False False False
Expand All @@ -1252,7 +1252,7 @@ def isnull(self):
3 Inf
4 -Inf
dtype: float64
>>> ser.isnull()
>>> ser.isna()
0 False
1 False
2 True
Expand All @@ -1265,17 +1265,17 @@ def isnull(self):
>>> idx = cudf.Index([1, 2, None, np.NaN, 0.32, np.inf])
>>> idx
Float64Index([1.0, 2.0, <NA>, <NA>, 0.32, Inf], dtype='float64')
>>> idx.isnull()
GenericIndex([False, False, True, True, False, False], dtype='bool')
>>> idx.isna()
array([False, False, True, True, False, False])
"""
data_columns = (col.isnull() for col in self._columns)
return self._from_data_like_self(zip(self._column_names, data_columns))

# Alias for isnull
isna = isnull
# Alias for isna
isnull = isna

@_cudf_nvtx_annotate
def notnull(self):
def notna(self):
"""
Identify non-missing values.

Expand Down Expand Up @@ -1315,7 +1315,7 @@ def notnull(self):
0 5 <NA> Alfred <NA>
1 6 1939-05-27 00:00:00.000000 Batman Batmobile
2 <NA> 1940-04-25 00:00:00.000000 Joker
>>> df.notnull()
>>> df.notna()
age born name toy
0 True False True False
1 True True True True
Expand All @@ -1331,7 +1331,7 @@ def notnull(self):
3 Inf
4 -Inf
dtype: float64
>>> ser.notnull()
>>> ser.notna()
0 True
1 True
2 False
Expand All @@ -1344,14 +1344,14 @@ def notnull(self):
>>> idx = cudf.Index([1, 2, None, np.NaN, 0.32, np.inf])
>>> idx
Float64Index([1.0, 2.0, <NA>, <NA>, 0.32, Inf], dtype='float64')
>>> idx.notnull()
GenericIndex([True, True, False, False, True, True], dtype='bool')
>>> idx.notna()
array([ True, True, False, False, True, True])
"""
data_columns = (col.notnull() for col in self._columns)
return self._from_data_like_self(zip(self._column_names, data_columns))

# Alias for notnull
notna = notnull
# Alias for notna
notnull = notna

@_cudf_nvtx_annotate
def searchsorted(
Expand Down
20 changes: 20 additions & 0 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,14 @@ def nunique(self):
def isna(self):
return cupy.zeros(len(self), dtype=bool)

isnull = isna

@_cudf_nvtx_annotate
def notna(self):
return cupy.ones(len(self), dtype=bool)

notnull = isna

@_cudf_nvtx_annotate
def _minmax(self, meth: str):
no_steps = len(self) - 1
Expand Down Expand Up @@ -1313,6 +1321,18 @@ def find_label_range(self, first, last):
end += 1
return begin, end

@_cudf_nvtx_annotate
def isna(self):
return self._column.isnull().values

isnull = isna

@_cudf_nvtx_annotate
def notna(self):
return self._column.notnull().values

notnull = notna

@_cudf_nvtx_annotate
def get_slice_bound(self, label, side, kind=None):
return self._values.get_slice_bound(label, side, kind)
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,14 @@ def test_index_copy_deep(idx, deep):
def test_index_isna(idx):
pidx = pd.Index(idx, name="idx")
gidx = cudf.core.index.Int64Index(idx, name="idx")
assert_eq(gidx.isna().to_numpy(), pidx.isna())
assert_eq(gidx.isna(), pidx.isna())


@pytest.mark.parametrize("idx", [[1, None, 3, None, 5]])
def test_index_notna(idx):
pidx = pd.Index(idx, name="idx")
gidx = cudf.core.index.Int64Index(idx, name="idx")
assert_eq(gidx.notna().to_numpy(), pidx.notna())
assert_eq(gidx.notna(), pidx.notna())


def test_rangeindex_slice_attr_name():
Expand Down