Skip to content

Commit

Permalink
Merge pull request #35 from cparmet/rename-assert-nulls
Browse files Browse the repository at this point in the history
Rename assert_not_null() and assert_null()
  • Loading branch information
cparmet authored Nov 11, 2024
2 parents 5a23bb4 + d46e3e3 commit 7d09d80
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ Here's what's in the doctor's bag.
- `.check.assert_less_than()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_less_than) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_less_than)
- `.check.assert_greater_than()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_greater_than) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_greater_than)
- `.check.assert_negative()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_negative) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_negative)
- `.check.assert_not_null()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_not_null) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_not_null)
- `.check.assert_null()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_null) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_null)
- `.check.assert_no_nulls()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_no_nulls) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_no_nulls)
- `.check.assert_all_nulls()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_all_nulls) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_all_nulls)
- `.check.assert_positive()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_positive) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_positive)
- `.check.assert_unique()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_unique) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_unique)

Expand Down
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Here's what's in the doctor's bag.
- `.check.assert_less_than()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_less_than) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_less_than)
- `.check.assert_greater_than()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_greater_than) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_greater_than)
- `.check.assert_negative()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_negative) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_negative)
- `.check.assert_not_null()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_not_null) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_not_null)
- `.check.assert_null()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_null) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_null)
- `.check.assert_no_nulls()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_no_nulls) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_no_nulls)
- `.check.assert_all_nulls()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_all_nulls) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_all_nulls)
- `.check.assert_positive()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_positive) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_positive)
- `.check.assert_unique()` - [DataFrame](https://cparmet.github.io/pandas-checks/API%20reference/DataFrameChecks/#pandas_checks.DataFrameChecks.DataFrameChecks.assert_unique) | [Series](https://cparmet.github.io/pandas-checks/API%20reference/SeriesChecks/#pandas_checks.SeriesChecks.SeriesChecks.assert_unique)

Expand Down
16 changes: 8 additions & 8 deletions pandas_checks/DataFrameChecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def assert_greater_than(
def assert_negative(
self,
subset: Union[str, List, None] = None,
assert_not_null: bool = True,
assert_no_nulls: bool = True,
pass_message: str = " ✔️ Assert negative passed ",
fail_message: str = " ㄨ Assert negative failed ",
raise_exception: bool = True,
Expand All @@ -351,7 +351,7 @@ def assert_negative(
Args:
subset: Optional, which column or columns to check the condition against.`
assert_not_null: Whether to also enforce that data has no nulls.
assert_no_nulls: Whether to also enforce that data has no nulls.
pass_message: Message to display if the condition passes.
fail_message: Message to display if the condition fails.
raise_exception: Whether to raise an exception if the condition fails.
Expand All @@ -362,7 +362,7 @@ def assert_negative(
The original DataFrame, unchanged.
"""

if assert_not_null:
if assert_no_nulls:
if _has_nulls(
data=self._obj[subset] if subset else self._obj,
fail_message=fail_message,
Expand All @@ -384,7 +384,7 @@ def assert_negative(
)
return self._obj

def assert_not_null(
def assert_no_nulls(
self,
subset: Union[str, List, None] = None,
pass_message: str = " ✔️ Assert no nulls passed ",
Expand Down Expand Up @@ -419,7 +419,7 @@ def assert_not_null(
)
return self._obj

def assert_null(
def assert_all_nulls(
self,
subset: Union[str, List, None] = None,
pass_message: str = " ✔️ Assert all nulls passed ",
Expand Down Expand Up @@ -457,7 +457,7 @@ def assert_null(
def assert_positive(
self,
subset: Union[str, List, None] = None,
assert_not_null: bool = True,
assert_no_nulls: bool = True,
pass_message: str = " ✔️ Assert positive passed ",
fail_message: str = " ㄨ Assert positive failed ",
raise_exception: bool = True,
Expand All @@ -468,7 +468,7 @@ def assert_positive(
Args:
subset: Optional, which column or columns to check the condition against. `
assert_not_null: Whether to also enforce that data has no nulls.
assert_no_nulls: Whether to also enforce that data has no nulls.
pass_message: Message to display if the condition passes.
fail_message: Message to display if the condition fails.
raise_exception: Whether to raise an exception if the condition fails.
Expand All @@ -478,7 +478,7 @@ def assert_positive(
Returns:
The original DataFrame, unchanged.
"""
if assert_not_null:
if assert_no_nulls:
if _has_nulls(
data=self._obj[subset] if subset else self._obj,
fail_message=fail_message,
Expand Down
16 changes: 8 additions & 8 deletions pandas_checks/SeriesChecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def assert_greater_than(

def assert_negative(
self,
assert_not_null: bool = True,
assert_no_nulls: bool = True,
pass_message: str = " ✔️ Assert negative passed ",
fail_message: str = " ㄨ Assert negative failed ",
raise_exception: bool = True,
Expand All @@ -327,7 +327,7 @@ def assert_negative(
"""Tests whether Series has all negative values. Optionally raises an exception. Does not modify the Series itself.
Args:
assert_not_null: Whether to also enforce that data has no nulls.
assert_no_nulls: Whether to also enforce that data has no nulls.
pass_message: Message to display if the condition passes.
fail_message: Message to display if the condition fails.
raise_exception: Whether to raise an exception if the condition fails.
Expand All @@ -338,7 +338,7 @@ def assert_negative(
The original Series, unchanged.
"""

if assert_not_null:
if assert_no_nulls:
if _has_nulls(
data=self._obj,
fail_message=fail_message,
Expand All @@ -359,7 +359,7 @@ def assert_negative(
)
return self._obj

def assert_not_null(
def assert_no_nulls(
self,
pass_message: str = " ✔️ Assert no nulls passed ",
fail_message: str = " ㄨ Assert no nulls failed ",
Expand Down Expand Up @@ -392,7 +392,7 @@ def assert_not_null(
)
return self._obj

def assert_null(
def assert_all_nulls(
self,
pass_message: str = " ✔️ Assert all nulls passed ",
fail_message: str = " ㄨ Assert all nulls failed ",
Expand Down Expand Up @@ -427,7 +427,7 @@ def assert_null(

def assert_positive(
self,
assert_not_null: bool = True,
assert_no_nulls: bool = True,
pass_message: str = " ✔️ Assert positive passed ",
fail_message: str = " ㄨ Assert positive failed ",
raise_exception: bool = True,
Expand All @@ -438,7 +438,7 @@ def assert_positive(
Args:
assert_not_null: Whether to also enforce that data has no nulls.
assert_no_nulls: Whether to also enforce that data has no nulls.
pass_message: Message to display if the condition passes.
fail_message: Message to display if the condition fails.
raise_exception: Whether to raise an exception if the condition fails.
Expand All @@ -448,7 +448,7 @@ def assert_positive(
Returns:
The original Series, unchanged.
"""
if assert_not_null:
if assert_no_nulls:
if _has_nulls(
data=self._obj,
fail_message=fail_message,
Expand Down
4 changes: 2 additions & 2 deletions pandas_checks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def _has_nulls(
if has_nulls:
if raise_exception:
raise exception_to_raise(
f"{fail_message}: Nulls present (to disable, pass `assert_not_null=False`)"
f"{fail_message}: Nulls present (to disable, pass `assert_no_nulls=False`)"
)
else:
_display_line(
lead_in=fail_message,
line="Nulls present (to disable, pass `assert_not_null=False`)",
line="Nulls present (to disable, pass `assert_no_nulls=False`)",
colors={
"lead_in_text_color": pd.get_option(
"pdchecks.fail_message_fg_color"
Expand Down
8 changes: 4 additions & 4 deletions tests/cases_dataframechecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def method_assert_negative():
)


def method_assert_not_null():
return lambda df, args: df.check.assert_not_null(
def method_assert_no_nulls():
return lambda df, args: df.check.assert_no_nulls(
subset=args["first_num_col"],
raise_exception=False,
)


def method_assert_null():
return lambda df, args: df.check.assert_null(
def method_assert_all_nulls():
return lambda df, args: df.check.assert_all_nulls(
subset=args["first_num_col"],
raise_exception=False,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/cases_serieschecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ def method_assert_negative():
)


def method_assert_not_null():
def method_assert_no_nulls():
return (
lambda s, _: s.check.assert_not_null(
lambda s, _: s.check.assert_no_nulls(
raise_exception=False,
),
False,
)


def method_assert_null():
def method_assert_all_nulls():
return (
lambda s, _: s.check.assert_null(
lambda s, _: s.check.assert_all_nulls(
raise_exception=False,
),
False,
Expand Down
24 changes: 12 additions & 12 deletions tests/test_dataframechecks_asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,35 +161,35 @@ def test_DataFrameChecks_assert_negative_one_null_pass(iris):
(
iris.assign(
one_null=lambda df: -df["sepal_length"].replace(5.1, np.nan)
).check.assert_negative(assert_not_null=False, subset=["one_null"])
).check.assert_negative(assert_no_nulls=False, subset=["one_null"])
)


def test_DataFrameChecks_assert_not_null_fail(iris):
def test_DataFrameChecks_assert_no_nulls_fail(iris):
with pytest.raises(DataError):
assert iris.assign(
one_null=lambda df: df["sepal_length"].replace(5.1, np.nan)
).check.assert_not_null(subset=["one_null"])
).check.assert_no_nulls(subset=["one_null"])


def test_DataFrameChecks_assert_not_null_pass(iris):
(iris.check.assert_not_null(subset=["species"]))
def test_DataFrameChecks_assert_no_nulls_pass(iris):
(iris.check.assert_no_nulls(subset=["species"]))


def test_DataFrameChecks_assert_null_fail(iris):
def test_DataFrameChecks_assert_all_nulls_fail(iris):
with pytest.raises(DataError):
assert iris.check.assert_null(subset=["species"])
assert iris.check.assert_all_nulls(subset=["species"])


def test_DataFrameChecks_assert_null_one_null_fail(iris):
def test_DataFrameChecks_assert_all_nulls_one_null_fail(iris):
with pytest.raises(DataError):
assert iris.assign(
one_null=lambda df: df["sepal_length"].replace(5.1, np.nan)
).check.assert_null(subset=["one_null"])
).check.assert_all_nulls(subset=["one_null"])


def test_DataFrameChecks_assert_null_pass(iris):
(iris.assign(all_nulls=np.nan).check.assert_null(subset=["all_nulls"]))
def test_DataFrameChecks_assert_all_nulls_pass(iris):
(iris.assign(all_nulls=np.nan).check.assert_all_nulls(subset=["all_nulls"]))


def test_DataFrameChecks_assert_positive_pass(iris):
Expand All @@ -215,7 +215,7 @@ def test_DataFrameChecks_assert_positive_one_null_pass(iris):
(
iris.assign(
one_null=lambda df: df["sepal_length"].replace(5.1, np.nan)
).check.assert_positive(assert_not_null=False, subset=["one_null"])
).check.assert_positive(assert_no_nulls=False, subset=["one_null"])
)


Expand Down
24 changes: 12 additions & 12 deletions tests/test_serieschecks_asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,35 +163,35 @@ def test_SeriesChecks_assert_negative_one_null_pass(iris):
(
iris.assign(one_null=lambda df: -df["sepal_length"].replace(5.1, np.nan))[
"one_null"
].check.assert_negative(assert_not_null=False)
].check.assert_negative(assert_no_nulls=False)
)


def test_SeriesChecks_assert_not_null_fail(iris):
def test_SeriesChecks_assert_no_nulls_fail(iris):
with pytest.raises(DataError):
assert iris.assign(one_null=lambda df: df["sepal_length"].replace(5.1, np.nan))[
"one_null"
].check.assert_not_null()
].check.assert_no_nulls()


def test_SeriesChecks_assert_not_null_pass(iris):
(iris["species"].check.assert_not_null())
def test_SeriesChecks_assert_no_nulls_pass(iris):
(iris["species"].check.assert_no_nulls())


def test_SeriesChecks_assert_null_fail(iris):
def test_SeriesChecks_assert_all_nulls_fail(iris):
with pytest.raises(DataError):
assert iris["species"].check.assert_null()
assert iris["species"].check.assert_all_nulls()


def test_SeriesChecks_assert_null_one_null_fail(iris):
def test_SeriesChecks_assert_all_nulls_one_null_fail(iris):
with pytest.raises(DataError):
assert iris.assign(one_null=lambda df: df["sepal_length"].replace(5.1, np.nan))[
"one_null"
].check.assert_null()
].check.assert_all_nulls()


def test_SeriesChecks_assert_null_pass(iris):
(iris.assign(all_nulls=np.nan)["all_nulls"].check.assert_null())
def test_SeriesChecks_assert_all_nulls_pass(iris):
(iris.assign(all_nulls=np.nan)["all_nulls"].check.assert_all_nulls())


def test_SeriesChecks_assert_positive_pass(iris):
Expand All @@ -215,7 +215,7 @@ def test_SeriesChecks_assert_positive_one_null_pass(iris):
(
iris.assign(one_null=lambda df: df["sepal_length"].replace(5.1, np.nan))[
"one_null"
].check.assert_positive(assert_not_null=False)
].check.assert_positive(assert_no_nulls=False)
)


Expand Down

0 comments on commit 7d09d80

Please sign in to comment.