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

typing fixes. #292

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/ci-additional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
environment-name: flox-tests
init-shell: bash
cache-environment: true
cache-env-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
create-args: |
python=${{ env.PYTHON_VERSION }}

Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
environment-name: flox-tests
init-shell: bash
cache-environment: true
cache-env-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
create-args: |
python=${{ env.PYTHON_VERSION }}
- name: Install flox
Expand Down
8 changes: 4 additions & 4 deletions flox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
T_DuckArray = Union[np.ndarray, DaskArray] # Any ?
T_By = T_DuckArray
T_Bys = tuple[T_By, ...]
T_ExpectIndex = Union[pd.Index]
T_ExpectIndex = pd.Index
T_ExpectIndexTuple = tuple[T_ExpectIndex, ...]
T_ExpectIndexOpt = Union[T_ExpectIndex, None]
T_ExpectIndexOptTuple = tuple[T_ExpectIndexOpt, ...]
Expand Down Expand Up @@ -314,7 +314,7 @@ def invert(x) -> tuple[np.ndarray, ...]:
items = tuple((k, set(k), v) for k, v in sorted_chunks_cohorts.items() if k)

merged_cohorts = {}
merged_keys = set()
merged_keys: set[tuple] = set()

# Now we iterate starting with the longest number of chunks,
# and then merge in cohorts that are present in a subset of those chunks
Expand Down Expand Up @@ -1895,7 +1895,7 @@ def groupby_reduce(
engine: T_EngineOpt = None,
reindex: bool | None = None,
finalize_kwargs: dict[Any, Any] | None = None,
) -> tuple[DaskArray, Unpack[tuple[np.ndarray | DaskArray, ...]]]: # type: ignore[misc] # Unpack not in mypy yet
) -> tuple[DaskArray, Unpack[tuple[np.ndarray | DaskArray, ...]]]:
"""
GroupBy reductions using tree reductions for dask.array

Expand Down Expand Up @@ -2223,4 +2223,4 @@ def groupby_reduce(

if is_bool_array and (_is_minmax_reduction(func) or _is_first_last_reduction(func)):
result = result.astype(bool)
return (result, *groups) # type: ignore[return-value] # Unpack not in mypy yet
return (result, *groups)
16 changes: 10 additions & 6 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,15 @@ def test_groupby_reduce(
elif func == "count":
expected_result = np.array(expected, dtype=np.intp)

(result, groups) = groupby_reduce(
(result, *groups) = groupby_reduce(
array,
by,
func=func,
expected_groups=expected_groups,
fill_value=123,
engine=engine,
)
(groups_array,) = groups
# we use pd.Index(expected_groups).to_numpy() which is always int64
# for the values in this test
if expected_groups is None:
Expand All @@ -196,7 +197,7 @@ def test_groupby_reduce(
else:
g_dtype = np.int64

assert_equal(groups, np.array([0, 1, 2], g_dtype))
assert_equal(groups_array, np.array([0, 1, 2], g_dtype))
assert_equal(expected_result, result)


Expand Down Expand Up @@ -795,11 +796,14 @@ def test_groupby_bins(chunk_labels, kwargs, chunks, engine, method) -> None:
labels = dask.array.from_array(labels, chunks=chunks)

with raise_if_dask_computes():
actual, groups = groupby_reduce(
actual, *groups = groupby_reduce(
array, labels, func="count", fill_value=0, engine=engine, method=method, **kwargs
)
(groups_array,) = groups
expected = np.array([3, 1, 0], dtype=np.intp)
for left, right in zip(groups, pd.IntervalIndex.from_arrays([1, 2, 4], [2, 4, 5]).to_numpy()):
for left, right in zip(
groups_array, pd.IntervalIndex.from_arrays([1, 2, 4], [2, 4, 5]).to_numpy()
):
assert left == right
assert_equal(actual, expected)

Expand Down Expand Up @@ -1034,13 +1038,13 @@ def test_bool_reductions(func, engine):
def test_map_reduce_blockwise_mixed() -> None:
t = pd.date_range("2000-01-01", "2000-12-31", freq="D").to_series()
data = t.dt.dayofyear
actual, _ = groupby_reduce(
actual, *_ = groupby_reduce(
dask.array.from_array(data.values, chunks=365),
t.dt.month,
func="mean",
method="map-reduce",
)
expected, _ = groupby_reduce(data, t.dt.month, func="mean")
expected, *_ = groupby_reduce(data, t.dt.month, func="mean")
assert_equal(expected, actual)


Expand Down
Loading