Skip to content

Fix the return type of e.g. agg.count to be INT64 by default #524

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

Merged
merged 1 commit into from
Dec 13, 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
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repos:
# We can probably remove `isort` if we come to trust `ruff --fix`,
# but we'll need to figure out the configuration to do this in `ruff`
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.1
hooks:
- id: isort
# Let's keep `pyupgrade` even though `ruff --fix` probably does most of it
Expand All @@ -61,12 +61,12 @@ repos:
- id: auto-walrus
args: [--line-length, "100"]
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 23.12.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
rev: v0.1.7
hooks:
- id: ruff
args: [--fix-only, --show-fixes]
Expand All @@ -79,7 +79,7 @@ repos:
additional_dependencies: &flake8_dependencies
# These versions need updated manually
- flake8==6.1.0
- flake8-bugbear==23.9.16
- flake8-bugbear==23.12.2
- flake8-simplify==0.21.0
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
Expand All @@ -94,11 +94,11 @@ repos:
additional_dependencies: [tomli]
files: ^(graphblas|docs)/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
rev: v0.1.7
hooks:
- id: ruff
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.8.1
rev: v0.9.1
hooks:
- id: sphinx-lint
args: [--enable, all, "--disable=line-too-long,leaked-markup"]
Expand Down
3 changes: 3 additions & 0 deletions graphblas/core/operator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def get_typed_op(op, dtype, dtype2=None, *, is_left_scalar=False, is_right_scala
from .agg import Aggregator, TypedAggregator

if isinstance(op, Aggregator):
# agg._any_dtype basically serves the same purpose as op._custom_dtype
if op._any_dtype is not None and op._any_dtype is not True:
return op[op._any_dtype]
return op[dtype]
if isinstance(op, TypedAggregator):
return op
Expand Down
2 changes: 1 addition & 1 deletion graphblas/tests/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_update(s):

def test_not_hashable(s):
with pytest.raises(TypeError, match="unhashable type"):
{s}
_ = {s}
with pytest.raises(TypeError, match="unhashable type"):
hash(s)

Expand Down
15 changes: 15 additions & 0 deletions graphblas/tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,21 @@ def test_reduce_agg(v):
assert s.is_empty


def test_reduce_agg_count_is_int64(v):
"""Aggregators that count should default to INT64 return dtype."""
assert v.dtype == dtypes.INT64
res = v.reduce(agg.count).new()
assert res.dtype == dtypes.INT64
assert res == 4
res = v.dup(dtypes.INT8).reduce(agg.count).new()
assert res.dtype == dtypes.INT64
assert res == 4
# Allow return dtype to be specified
res = v.dup(dtypes.INT8).reduce(agg.count[dtypes.INT16]).new()
assert res.dtype == dtypes.INT16
assert res == 4


@pytest.mark.skipif("not suitesparse")
def test_reduce_agg_argminmax(v):
assert v.reduce(agg.ss.argmin).new() == 6
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Use, adjust, copy/paste, etc. as necessary to answer your questions.
# This may be helpful when updating dependency versions in CI.
# Tip: add `--json` for more information.
conda search 'flake8-bugbear[channel=conda-forge]>=23.9.16'
conda search 'flake8-bugbear[channel=conda-forge]>=23.12.2'
conda search 'flake8-simplify[channel=conda-forge]>=0.21.0'
conda search 'numpy[channel=conda-forge]>=1.26.0'
conda search 'pandas[channel=conda-forge]>=2.1.2'
Expand Down