Skip to content

Commit

Permalink
πŸ› Fix ZeroDivisionError in inspect (#75)
Browse files Browse the repository at this point in the history
* πŸ› Fix zero division eror in inspect

* πŸ‘· Run 3.10

* πŸ§ͺ Add tests
  • Loading branch information
sunnyosun authored Mar 21, 2024
1 parent 368016a commit 50ff369
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
Expand All @@ -34,6 +34,6 @@ jobs:
- run: nox -s lint
- run: nox -s build
- uses: codecov/codecov-action@v2
if: matrix.python-version == '3.9'
if: matrix.python-version == '3.10'
with:
token: ${{ secrets.CODECOV_TOKEN }}
9 changes: 9 additions & 0 deletions lamin_utils/_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def _validate_stats(identifiers: Iterable, matches: "np.ndarray"):
nonval = _unique_rm_empty(df_val.index[~df_val["__validated__"]]).tolist()

n_unique = len(val) + len(nonval)
if n_unique == 0:
return InspectResult(
validated_df=df_val,
validated=val,
nonvalidated=nonval,
frac_validated=0,
n_empty=0,
n_unique=0,
)
n_empty = df_val.shape[0] - n_unique
frac_nonval = round(len(nonval) / n_unique * 100, 1)
frac_val = 100 - frac_nonval
Expand Down
10 changes: 10 additions & 0 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def test_inspect_empty_dup_input(genes):
assert result.non_validated == []


def test_inspect_zero_identifiers():
result = inspect(
df=pd.DataFrame(),
identifiers=pd.Series([]),
field="symbol",
)
assert result.validated == []
assert result.non_validated == []


def test_inspect_empty_df():
import numpy as np
import pandas as pd
Expand Down

0 comments on commit 50ff369

Please sign in to comment.