Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into rename-alpha-data-m…
Browse files Browse the repository at this point in the history
…odels
  • Loading branch information
silvavelosa committed Sep 27, 2022
2 parents d7211c4 + aa3f52b commit e33ad17
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [4.6.0] - 2022-09-26
### Changed
- Change geospatial.aggregate_features to support `aggregate_output`

## [4.5.4] - 2022-09-19
### Fixed
- The raw rows insert endpoint is now subject to the same retry logic as other idempotent endpoints.
Expand Down
20 changes: 17 additions & 3 deletions cognite/client/_api/geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,12 @@ def stream_features(
def aggregate_features(
self,
feature_type_external_id: str,
property: str,
aggregates: Sequence[str],
property: str = None,
aggregates: Sequence[str] = None,
filter: Optional[Dict[str, Any]] = None,
group_by: Sequence[str] = None,
order_by: Sequence[OrderSpec] = None,
output: Dict[str, Any] = None,
) -> FeatureAggregateList:
"""`Aggregate filtered features`
<https://docs.cognite.com/api/v1/#operation/aggregateFeatures>
Expand All @@ -780,6 +781,7 @@ def aggregate_features(
aggregates (Sequence[str]): list of aggregates to be calculated
group_by (Sequence[str]): list of properties to group by with
order_by (Sequence[OrderSpec]): the order specification
output (Dict[str, Any]): the aggregate output
Returns:
FeatureAggregateList: the filtered features
Expand All @@ -794,17 +796,28 @@ def aggregate_features(
... feature_type_external_id="my_feature_type",
... feature=Feature(external_id="my_feature", temperature=12.4)
... )
>>> res = c.geospatial.aggregate_features(
>>> res_deprecated = c.geospatial.aggregate_features(
... feature_type_external_id="my_feature_type",
... filter={"range": {"property": "temperature", "gt": 12.0}},
... property="temperature",
... aggregates=["max", "min"],
... group_by=["category"],
... order_by=[OrderSpec("category", "ASC")]
... ) # deprecated
>>> res = c.geospatial.aggregate_features(
... feature_type_external_id="my_feature_type",
... filter={"range": {"property": "temperature", "gt": 12.0}},
... group_by=["category"],
... order_by=[OrderSpec("category", "ASC")],
... output={"min_temperature": {"min": {"property": "temperature"}},
... "max_volume": {"max": {"property": "volume"}}
... }
... )
>>> for a in res:
... # loop over aggregates in different groups
"""
if property or aggregates:
warnings.warn("property and aggregates are deprecated, use output instead.", DeprecationWarning)
resource_path = self._feature_resource_path(feature_type_external_id) + "/aggregate"
cls = FeatureAggregateList
order = None if order_by is None else [f"{item.property}:{item.direction}" for item in order_by]
Expand All @@ -816,6 +829,7 @@ def aggregate_features(
"aggregates": aggregates,
"groupBy": group_by,
"sort": order,
"output": output,
},
)
return cls._load(res.json()["items"], cognite_client=self._cognite_client)
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "4.5.5"
__version__ = "4.6.1"
__api_subversion__ = "V20220125"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "cognite-sdk"

version = "4.5.5"
version = "4.6.1"

description = "Cognite Python SDK"
readme = "README.md"
Expand Down
8 changes: 8 additions & 0 deletions tests/tests_integration/test_api/test_geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,11 @@ def test_aggregate_with_order_by(self, cognite_client, test_feature_type, test_f
order_by=[OrderSpec("externalId", "ASC")],
)
assert external_ids == [item.external_id for item in res_asc]

def test_aggregate_output(self, cognite_client, test_feature_type, test_features):
res = cognite_client.geospatial.aggregate_features(
feature_type_external_id=test_feature_type.external_id,
filter={"range": {"property": "temperature", "gt": 12.0, "lt": 13.0}},
output={"count": {"count": {"property": "temperature"}}},
)
assert res[0].count == 1

0 comments on commit e33ad17

Please sign in to comment.