Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaredoug committed Dec 26, 2023
1 parent 0358cd7 commit 3dafe6d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[flake8]
ignore =
# https://github.com/psf/black#slices
E203,
# https://github.com/psf/black#line-length
E501,
# https://github.com/psf/black#line-breaks--binary-operators
W503,
# we don't require docstrings by default
D100, D101, D102, D103, D104, D105, D106, D107,
# this check is overly picky about RNG usage when it might not matter
# https://github.snooguts.net/reddit/docker-reddit-lint.py/pull/2
DUO102,
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test: deps
lint: deps
@echo "Linting..."
python -m flake8 --max-line-length=120 --ignore=E203,W503,E501,E722,E731,W605 --exclude=venv,build,dist,docs,*.egg-info,*.egg,*.pyc,*.pyo,*.git,__pycache__,.pytest_cache,.benchmarks
mypy searcharray tests
mypy searcharray test


benchmark_dry_run: deps
Expand Down
7 changes: 7 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[mypy]

[mypy-sortednp]
ignore_missing_imports = True

[mypy-pandas.tests.*]
ignore_missing_imports = True
22 changes: 19 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,49 @@ asttokens==2.4.1
build==1.0.3
certifi==2023.7.22
charset-normalizer==3.3.2
contourpy==1.2.0
coverage==7.3.2
cycler==0.12.1
decorator==5.1.1
docutils==0.20.1
executing==2.0.1
flake8==6.1.0
fonttools==4.46.0
idna==3.4
importlib-metadata==6.8.0
iniconfig==2.0.0
ipython==8.17.2
jaraco.classes==3.3.0
jedi==0.19.1
keyring==24.3.0
kiwisolver==1.4.5
markdown-it-py==3.0.0
matplotlib==3.8.2
matplotlib-inline==0.1.6
mccabe==0.7.0
mdurl==0.1.2
more-itertools==10.1.0
mypy==1.8.0
mypy-extensions==1.0.0
nh3==0.2.14
numpy==1.26.1
packaging==23.2
pandas==2.1.2
pandas-stubs==2.1.4.231218
parso==0.8.3
pexpect==4.8.0
Pillow==10.1.0
pkginfo==1.9.6
pluggy==1.3.0
prompt-toolkit==3.0.39
ptyprocess==0.7.0
pure-eval==0.2.2
py-cpuinfo==9.0.0
pycodestyle==2.11.1
pyflakes==3.1.0
pygal==3.0.4
Pygments==2.16.1
pyparsing==3.1.1
pyproject_hooks==1.0.0
pyroaring==0.4.4
pytest==7.4.3
Expand All @@ -44,16 +58,18 @@ requests==2.31.0
requests-toolbelt==1.0.0
rfc3986==2.0.0
rich==13.6.0
scipy==1.11.3
scipy==1.11.4
searcharray==0.0.1
six==1.16.0
snakeviz==2.2.0
sortednp==0.4.1
stack-data==0.6.3
tornado==6.4
traitlets==5.13.0
twine==4.0.2
types-pytz==2023.3.1.1
typing_extensions==4.9.0
tzdata==2023.3
urllib3==2.1.0
wcwidth==0.2.9
zipp==3.17.0
flake8==6.1.0
mypy==1.8.0
3 changes: 2 additions & 1 deletion searcharray/phrase/middle_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import sortednp as snp
from copy import deepcopy
from typing import List, Tuple, Dict, Union
from typing import List, Tuple, Dict, Union, cast
from searcharray.utils.roaringish import RoaringishEncoder, convert_keys
import numbers
import logging
Expand Down Expand Up @@ -293,6 +293,7 @@ def positions(self, term_id: int, key) -> Union[List[np.ndarray], np.ndarray]:
return [np.array([], dtype=np.uint32)]
if len(decoded) != len(doc_ids):
# Fill non matches
decoded = cast(List[Tuple[np.uint64, np.ndarray]], decoded)
as_dict: Dict[np.uint64, np.ndarray] = dict(decoded)
decs = []
for doc_id in doc_ids:
Expand Down
3 changes: 2 additions & 1 deletion searcharray/postings.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ def doc_freq(self, token: str) -> int:
raise TypeError("Expected a string")
# Count number of rows where the term appears
term_freq = self.term_freq(token)
return np.sum(term_freq > 0)
gt_0 = term_freq > 0
return np.sum(gt_0).astype(int)

def doc_lengths(self) -> np.ndarray:
return self.doc_lens
Expand Down
6 changes: 4 additions & 2 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytest
from typing import Dict, Any
from typing import Dict, Any, cast, Sequence, Type, Union
import cProfile
import sys


def w_scenarios(scenarios: Dict[str, Dict[str, Any]]):
"""Decorate for parametrizing tests that names the scenarios and params."""
return pytest.mark.parametrize(
[key for key in scenarios.values()][0].keys(),
cast(Sequence[str], [key for key in scenarios.values()][0].keys()),
[tuple(scenario.values()) for scenario in scenarios.values()],
ids=list(scenarios.keys())
)
Expand Down Expand Up @@ -42,6 +42,8 @@ def run(self, func, *args, **kwargs):
return rval


Profiler: Union[Type[JustBenchmarkProfiler], Type[CProfileProfiler]]

if '--benchmark-disable' in sys.argv:
Profiler = CProfileProfiler
else:
Expand Down

0 comments on commit 3dafe6d

Please sign in to comment.