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

[REVIEW] Series/DataFrame notnull #2844

Merged
merged 3 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- PR #2786 Add benchmarks option to root build.sh
- PR #2773 Add Fisher's unbiased kurtosis and skew for Series/DataFrame
- PR #2748 Parquet Reader: Add option to specify loading of PANDAS index
- PR #2844 ADd Series/DataFrame notnull
kkraus14 marked this conversation as resolved.
Show resolved Hide resolved

## Improvements

Expand Down
17 changes: 11 additions & 6 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3063,20 +3063,25 @@ def _create_output_frame(data, percentiles=None):

return output_frame

def isnull(self, **kwargs):
def isnull(self):
"""Identify missing values in a DataFrame.
"""
return self._apply_support_method("isnull", **kwargs)
return self._apply_support_method("isnull")

def isna(self, **kwargs):
def isna(self):
"""Identify missing values in a DataFrame. Alias for isnull.
"""
return self.isnull(**kwargs)
return self.isnull()

def notna(self, **kwargs):
def notna(self):
"""Identify non-missing values in a DataFrame.
"""
return self._apply_support_method("notna", **kwargs)
return self._apply_support_method("notna")

def notnull(self):
"""Identify non-missing values in a DataFrame. Alias for notna.
"""
return self.notna()

def to_pandas(self):
"""
Expand Down
5 changes: 5 additions & 0 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,11 @@ def notna(self):
mask = cudautils.notna_mask(self.data, self.nullmask.mem)
return Series(mask, name=self.name, index=self.index)

def notnull(self):
"""Identify non-missing values in a Series. Alias for notna.
"""
return self.notna()

def nans_to_nulls(self):
"""
Convert nans (if any) to nulls
Expand Down
17 changes: 16 additions & 1 deletion python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ def test_isnull_isna():
assert_eq(ps.isna(), gs.isna())


def test_notna():
def test_notna_notnull():
# float & strings some missing
ps = pd.DataFrame(
{
Expand All @@ -2538,12 +2538,16 @@ def test_notna():
gs = DataFrame.from_pandas(ps)
assert_eq(ps.notna(), gs.notna())
assert_eq(ps.a.notna(), gs.a.notna())
assert_eq(ps.notnull(), gs.notnull())
assert_eq(ps.a.notnull(), gs.a.notnull())

# integer & string none missing
ps = pd.DataFrame({"a": [0, 1, 2, 3, 4], "b": ["a", "b", "u", "h", "d"]})
gs = DataFrame.from_pandas(ps)
assert_eq(ps.notna(), gs.notna())
assert_eq(ps.a.notna(), gs.a.notna())
assert_eq(ps.notnull(), gs.notnull())
assert_eq(ps.a.notnull(), gs.a.notnull())

# all missing
ps = pd.DataFrame(
Expand All @@ -2552,35 +2556,46 @@ def test_notna():
gs = DataFrame.from_pandas(ps)
assert_eq(ps.notna(), gs.notna())
assert_eq(ps.a.notna(), gs.a.notna())
assert_eq(ps.notnull(), gs.notnull())
assert_eq(ps.a.notnull(), gs.a.notnull())

# empty
ps = pd.DataFrame({"a": []})
gs = DataFrame.from_pandas(ps)
assert_eq(ps.notna(), gs.notna())
assert_eq(ps.a.notna(), gs.a.notna())
assert_eq(ps.notnull(), gs.notnull())
assert_eq(ps.a.notnull(), gs.a.notnull())

# one missing
ps = pd.DataFrame({"a": [np.nan], "b": [None]})
gs = DataFrame.from_pandas(ps)
assert_eq(ps.notna(), gs.notna())
assert_eq(ps.a.notna(), gs.a.notna())
assert_eq(ps.notnull(), gs.notnull())
assert_eq(ps.a.notnull(), gs.a.notnull())

# strings missing
ps = pd.DataFrame({"a": ["a", "b", "c", None, "e"]})
gs = DataFrame.from_pandas(ps)
assert_eq(ps.notna(), gs.notna())
assert_eq(ps.a.notna(), gs.a.notna())
assert_eq(ps.notnull(), gs.notnull())
assert_eq(ps.a.notnull(), gs.a.notnull())

# strings none missing
ps = pd.DataFrame({"a": ["a", "b", "c", "d", "e"]})
gs = DataFrame.from_pandas(ps)
assert_eq(ps.notna(), gs.notna())
assert_eq(ps.a.notna(), gs.a.notna())
assert_eq(ps.notnull(), gs.notnull())
assert_eq(ps.a.notnull(), gs.a.notnull())

# unnamed series
ps = pd.Series([0, 1, 2, np.nan, 4, None, 6])
gs = Series.from_pandas(ps)
assert_eq(ps.notna(), gs.notna())
assert_eq(ps.notnull(), gs.notnull())


def test_ndim():
Expand Down