-
Notifications
You must be signed in to change notification settings - Fork 27
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
[DOGE-106] Instance aggregate/search limit=None means maximum #2121
base: master
Are you sure you want to change the base?
Changes from 3 commits
18b4a91
12554da
4e38e80
86161c9
48ae172
94cde08
dc76d44
8ba4c98
0b1fadb
5040de1
75e51af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -71,15 +71,15 @@ | |||||
) | ||||||
from cognite.client.data_classes.data_modeling.views import View | ||||||
from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter | ||||||
from cognite.client.utils._auxiliary import load_yaml_or_json | ||||||
from cognite.client.utils._auxiliary import is_unlimited, load_yaml_or_json | ||||||
from cognite.client.utils._concurrency import ConcurrencySettings | ||||||
from cognite.client.utils._identifier import DataModelingIdentifierSequence | ||||||
from cognite.client.utils._retry import Backoff | ||||||
from cognite.client.utils._text import random_string | ||||||
from cognite.client.utils.useful_types import SequenceNotStr | ||||||
|
||||||
if TYPE_CHECKING: | ||||||
from cognite.client import CogniteClient | ||||||
from cognite.client import ClientConfig, CogniteClient | ||||||
|
||||||
_FILTERS_SUPPORTED: frozenset[type[Filter]] = _BASIC_FILTERS.union( | ||||||
{filters.Nested, filters.HasData, filters.MatchAll, filters.Overlaps, filters.InstanceReferences} | ||||||
|
@@ -164,6 +164,10 @@ def _load(data: dict, cognite_client: CogniteClient | None = None) -> NodeApply | |||||
class InstancesAPI(APIClient): | ||||||
_RESOURCE_PATH = "/models/instances" | ||||||
|
||||||
def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None: | ||||||
super().__init__(config, api_version, cognite_client) | ||||||
self._AGGREGATE_LIMIT = 1000 | ||||||
|
||||||
@overload | ||||||
def __call__( | ||||||
self, | ||||||
|
@@ -1202,7 +1206,7 @@ def aggregate( | |||||
target_units: list[TargetUnit] | None = None, | ||||||
space: str | SequenceNotStr[str] | None = None, | ||||||
filter: Filter | dict[str, Any] | None = None, | ||||||
limit: int = DEFAULT_LIMIT_READ, | ||||||
limit: int | None = DEFAULT_LIMIT_READ, | ||||||
) -> AggregatedNumberedValue: ... | ||||||
|
||||||
@overload | ||||||
|
@@ -1217,7 +1221,7 @@ def aggregate( | |||||
target_units: list[TargetUnit] | None = None, | ||||||
space: str | SequenceNotStr[str] | None = None, | ||||||
filter: Filter | dict[str, Any] | None = None, | ||||||
limit: int = DEFAULT_LIMIT_READ, | ||||||
limit: int | None = DEFAULT_LIMIT_READ, | ||||||
) -> list[AggregatedNumberedValue]: ... | ||||||
|
||||||
@overload | ||||||
|
@@ -1232,7 +1236,7 @@ def aggregate( | |||||
target_units: list[TargetUnit] | None = None, | ||||||
space: str | SequenceNotStr[str] | None = None, | ||||||
filter: Filter | dict[str, Any] | None = None, | ||||||
limit: int = DEFAULT_LIMIT_READ, | ||||||
limit: int | None = DEFAULT_LIMIT_READ, | ||||||
) -> InstanceAggregationResultList: ... | ||||||
|
||||||
def aggregate( | ||||||
|
@@ -1246,7 +1250,7 @@ def aggregate( | |||||
target_units: list[TargetUnit] | None = None, | ||||||
space: str | SequenceNotStr[str] | None = None, | ||||||
filter: Filter | dict[str, Any] | None = None, | ||||||
limit: int = DEFAULT_LIMIT_READ, | ||||||
limit: int | None = DEFAULT_LIMIT_READ, | ||||||
) -> AggregatedNumberedValue | list[AggregatedNumberedValue] | InstanceAggregationResultList: | ||||||
"""`Aggregate data across nodes/edges <https://developer.cognite.com/api/v1/#tag/Instances/operation/aggregateInstances>`_ | ||||||
|
||||||
|
@@ -1260,7 +1264,8 @@ def aggregate( | |||||
target_units (list[TargetUnit] | None): Properties to convert to another unit. The API can only convert to another unit if a unit has been defined as part of the type on the underlying container being queried. | ||||||
space (str | SequenceNotStr[str] | None): Restrict instance aggregate query to the given space (or list of spaces). | ||||||
filter (Filter | dict[str, Any] | None): Advanced filtering of instances. | ||||||
limit (int): Maximum number of instances to return. Defaults to 25. | ||||||
limit (int | None): Maximum number of instances to return. Defaults to 25. Will return the maximum number | ||||||
of results (1000) if set to None, -1, or math.inf. | ||||||
|
||||||
Returns: | ||||||
AggregatedNumberedValue | list[AggregatedNumberedValue] | InstanceAggregationResultList: Node or edge aggregation results. | ||||||
|
@@ -1282,7 +1287,11 @@ def aggregate( | |||||
|
||||||
self._validate_filter(filter) | ||||||
filter = self._merge_space_into_filter(instance_type, space, filter) | ||||||
body: dict[str, Any] = {"view": view.dump(camel_case=True), "instanceType": instance_type, "limit": limit} | ||||||
body: dict[str, Any] = { | ||||||
"view": view.dump(camel_case=True), | ||||||
"instanceType": instance_type, | ||||||
"limit": self._AGGREGATE_LIMIT if is_unlimited(limit) or limit is None else limit, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
ref its implementation: def is_unlimited(limit: float | int | None) -> bool:
return limit in {None, -1, math.inf} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok then it is me that did not trust mypy |
||||||
} | ||||||
is_single = isinstance(aggregates, (dict, MetricAggregation)) | ||||||
aggregate_seq: Sequence[MetricAggregation | dict] = ( | ||||||
[aggregates] if isinstance(aggregates, (dict, MetricAggregation)) else aggregates | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
__version__ = "7.73.4" | ||
__version__ = "7.73.5" | ||
|
||
__api_subversion__ = "20230101" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these be class variables instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that could be. Consistently in the SDK we have limits as instance
attributes. Suggest that if we move these two class variables, we do it everywhere, which should in that case be a separate PR.