Skip to content

Commit

Permalink
Fix some typing errors in asv_bench and tests (#253)
Browse files Browse the repository at this point in the history
* Let mypy check asv_bench

* Update pyproject.toml

* Update pyproject.toml

* Update pyproject.toml

* Update pyproject.toml

* Update pyproject.toml

* Update pyproject.toml

* Update test_core.py

* Update test_core.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update test_core.py

* Update cohorts.py

* fix asv test

* split-reduce is old name

* Update test_core.py

* the exclude doesn't seem to work anyway

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Illviljan and pre-commit-ci[bot] committed Jul 8, 2023
1 parent 53c108c commit 40b300c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions asv_bench/benchmarks/cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def track_num_layers(self):
)[0]
return len(result.dask.layers)

track_num_tasks.unit = "tasks"
track_num_tasks_optimized.unit = "tasks"
track_num_layers.unit = "layers"
track_num_tasks.unit = "tasks" # type: ignore[attr-defined] # Lazy
track_num_tasks_optimized.unit = "tasks" # type: ignore[attr-defined] # Lazy
track_num_layers.unit = "layers" # type: ignore[attr-defined] # Lazy


class NWMMidwest(Cohorts):
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def construct_member(groups) -> dict[str, Any]:
]
self.kwargs = {
"agg": flox.aggregations._initialize_aggregation(
"sum", "float64", np.float64, 0, None, {}
"sum", "float64", np.float64, 0, 0, {}
),
"axis": (3,),
}
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ known-third-party = [

[tool.mypy]
allow_redefinition = true
exclude = "properties|asv_bench|doc|tests|flycheck"
files = "flox/*.py"
files = "**/*.py"
show_error_codes = true
warn_unused_ignores = true

Expand All @@ -115,7 +114,8 @@ module=[
"cftime",
"dask.*",
"importlib_metadata",
"numpy_groupies",
"numba",
"numpy_groupies.*",
"matplotlib.*",
"pandas",
"setuptools",
Expand Down
14 changes: 8 additions & 6 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def dask_array_ones(*args):
)

if TYPE_CHECKING:
from flox.core import T_Engine, T_ExpectedGroupsOpt, T_Func2
from flox.core import T_Agg, T_Engine, T_ExpectedGroupsOpt, T_Method


def _get_array_func(func: str) -> Callable:
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_alignment_error():
)
def test_groupby_reduce(
engine: T_Engine,
func: T_Func2,
func: T_Agg,
array: np.ndarray,
by: np.ndarray,
expected: list[float],
Expand Down Expand Up @@ -992,14 +992,14 @@ def test_map_reduce_blockwise_mixed() -> None:
dask.array.from_array(data.values, chunks=365),
t.dt.month,
func="mean",
method="split-reduce",
method="map-reduce",
)
expected, _ = groupby_reduce(data, t.dt.month, func="mean")
assert_equal(expected, actual)


@requires_dask
@pytest.mark.parametrize("method", ["split-reduce", "blockwise", "map-reduce", "cohorts"])
@pytest.mark.parametrize("method", ["blockwise", "map-reduce", "cohorts"])
def test_group_by_datetime(engine, method):
kwargs = dict(
func="mean",
Expand Down Expand Up @@ -1356,13 +1356,15 @@ def test_validate_reindex_map_reduce(


def test_validate_reindex() -> None:
for method in ["map-reduce", "cohorts"]:
methods: list[T_Method] = ["map-reduce", "cohorts"]
for method in methods:
with pytest.raises(NotImplementedError):
_validate_reindex(
True, "argmax", method, expected_groups=None, any_by_dask=False, is_dask_array=True
)

for method in ["blockwise", "cohorts"]:
methods: list[T_Method] = ["blockwise", "cohorts"]
for method in methods:
with pytest.raises(ValueError):
_validate_reindex(
True, "sum", method, expected_groups=None, any_by_dask=False, is_dask_array=True
Expand Down

0 comments on commit 40b300c

Please sign in to comment.