Skip to content

Commit 397cf5b

Browse files
committed
Fix pre-commit lint and formatting issues
1 parent 704fb8f commit 397cf5b

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

integration/test_collection_aggregate.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -887,36 +887,45 @@ def test_hybrid_bm25_operators(collection_factory: CollectionFactory) -> None:
887887

888888

889889
def test_aggregate_empty_result_none_values(collection_factory: CollectionFactory) -> None:
890-
"""Test for issue #11219: aggregate metrics should be None for empty result sets, not 0/0.0"""
890+
"""Test for issue #11219: aggregate metrics should be None for empty result sets, not 0/0.0."""
891891
collection = collection_factory(
892892
properties=[
893-
Property(name="bucket", data_type=DataType.INT, index_filterable=True, index_range_filters=True),
893+
Property(
894+
name="bucket",
895+
data_type=DataType.INT,
896+
index_filterable=True,
897+
index_range_filters=True,
898+
),
894899
Property(name="intVal", data_type=DataType.INT),
895900
Property(name="numberVal", data_type=DataType.NUMBER),
896901
],
897902
vectorizer_config=Configure.Vectorizer.none(),
898903
inverted_index_config=Configure.inverted_index(index_null_state=True),
899904
)
900-
905+
901906
if collection._connection._weaviate_version.is_lower_than(1, 29, 0):
902907
pytest.skip("gRPC aggregates are only supported in versions 1.29.0 and higher")
903-
908+
904909
# Insert one object with bucket=0
905910
collection.data.insert({"bucket": 0, "intVal": 123, "numberVal": 456.78})
906-
911+
907912
# Query with a filter that returns no results (bucket=99 doesn't exist)
908913
res: AggregateReturn = collection.aggregate.over_all(
909914
filters=Filter.by_property("bucket").equal(99),
910915
total_count=True,
911916
return_metrics=[
912-
Metrics("intVal").integer(count=True, maximum=True, mean=True, median=True, minimum=True, mode=True, sum_=True),
913-
Metrics("numberVal").number(count=True, maximum=True, mean=True, median=True, minimum=True, mode=True, sum_=True),
917+
Metrics("intVal").integer(
918+
count=True, maximum=True, mean=True, median=True, minimum=True, mode=True, sum_=True
919+
),
920+
Metrics("numberVal").number(
921+
count=True, maximum=True, mean=True, median=True, minimum=True, mode=True, sum_=True
922+
),
914923
],
915924
)
916-
925+
917926
# Verify total_count is 0
918927
assert res.total_count == 0
919-
928+
920929
# Verify integer metrics: count should be 0, all other metrics should be None (not 0)
921930
int_metrics = res.properties["intVal"]
922931
assert isinstance(int_metrics, AggregateInteger)
@@ -927,7 +936,7 @@ def test_aggregate_empty_result_none_values(collection_factory: CollectionFactor
927936
assert int_metrics.minimum is None, "minimum should be None for empty result set"
928937
assert int_metrics.mode is None, "mode should be None for empty result set"
929938
assert int_metrics.sum_ is None, "sum_ should be None for empty result set"
930-
939+
931940
# Verify number metrics: count should be 0, all other metrics should be None (not 0.0)
932941
number_metrics = res.properties["numberVal"]
933942
assert isinstance(number_metrics, AggregateNumber)
@@ -938,4 +947,3 @@ def test_aggregate_empty_result_none_values(collection_factory: CollectionFactor
938947
assert number_metrics.minimum is None, "minimum should be None for empty result set"
939948
assert number_metrics.mode is None, "mode should be None for empty result set"
940949
assert number_metrics.sum_ is None, "sum_ should be None for empty result set"
941-

weaviate/collections/aggregations/base_executor.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,32 @@ def __parse_property_grpc(
279279
elif aggregation.HasField("number"):
280280
return AggregateNumber(
281281
count=aggregation.number.count,
282-
maximum=aggregation.number.maximum if aggregation.number.HasField("maximum") else None,
282+
maximum=aggregation.number.maximum
283+
if aggregation.number.HasField("maximum")
284+
else None,
283285
mean=aggregation.number.mean if aggregation.number.HasField("mean") else None,
284286
median=aggregation.number.median if aggregation.number.HasField("median") else None,
285-
minimum=aggregation.number.minimum if aggregation.number.HasField("minimum") else None,
287+
minimum=aggregation.number.minimum
288+
if aggregation.number.HasField("minimum")
289+
else None,
286290
mode=aggregation.number.mode if aggregation.number.HasField("mode") else None,
287291
sum_=aggregation.number.sum if aggregation.number.HasField("sum") else None,
288292
)
289293
elif aggregation.HasField("boolean"):
290294
return AggregateBoolean(
291295
count=aggregation.boolean.count,
292-
percentage_false=aggregation.boolean.percentage_false if aggregation.boolean.HasField("percentage_false") else None,
293-
percentage_true=aggregation.boolean.percentage_true if aggregation.boolean.HasField("percentage_true") else None,
294-
total_false=aggregation.boolean.total_false if aggregation.boolean.HasField("total_false") else None,
295-
total_true=aggregation.boolean.total_true if aggregation.boolean.HasField("total_true") else None,
296+
percentage_false=aggregation.boolean.percentage_false
297+
if aggregation.boolean.HasField("percentage_false")
298+
else None,
299+
percentage_true=aggregation.boolean.percentage_true
300+
if aggregation.boolean.HasField("percentage_true")
301+
else None,
302+
total_false=aggregation.boolean.total_false
303+
if aggregation.boolean.HasField("total_false")
304+
else None,
305+
total_true=aggregation.boolean.total_true
306+
if aggregation.boolean.HasField("total_true")
307+
else None,
296308
)
297309
elif aggregation.HasField("date"):
298310
return AggregateDate(

0 commit comments

Comments
 (0)