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

DM-2412 fix aggregate property casing + add files tests cleanup #2059

Merged
merged 8 commits into from
Dec 10, 2024
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
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [7.70.3] - 2024-12-11
### Fixed
- Aggregation requests with custom properties, like a metadata key, are no longer converted to camelCase
automatically.

## [7.70.2] - 2024-12-04
### Fixed
- Retrieving `ExtractionPipeline` either with `client.extraction_pipelines.retrieve` or
`client.extraction_pipelines.list` no longer raises a `KeyError` if any of the pipline properties have a contact
with a `None` value.
- Retrieving `ExtractionPipeline` no longer raises a `KeyError` if any of the piplines have a contact with missing fields.

## [7.70.1] - 2024-12-04
### Fixed
- Fix `workflows.executions.retrieve_detailed` type for `SimulationInputOverride` to allow for `None` value for `unit`.

## [7.70.0] - 2024-12-02
### Added
- Workflow support for "simulation" task type.
- Workflow support for "simulation" task type.

## [7.69.4] - 2024-12-02
### Added
Expand Down
7 changes: 3 additions & 4 deletions cognite/client/_api/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,15 @@ def aggregate_cardinality_values(

def aggregate_cardinality_properties(
self,
path: DocumentProperty | SourceFileProperty | list[str] | str,
path: SourceFileProperty | list[str] = SourceFileProperty.metadata,
query: str | None = None,
filter: Filter | dict[str, Any] | None = None,
aggregate_filter: AggregationFilter | dict[str, Any] | None = None,
) -> int:
"""`Find approximate paths count for documents. <https://developer.cognite.com/api#tag/Documents/operation/documentsAggregate>`_

Args:
path (DocumentProperty | SourceFileProperty | list[str] | str): The scope in every document to aggregate properties. The only value allowed now is ["metadata"]. It means to aggregate only metadata properties (aka keys).
path (SourceFileProperty | list[str]): The scope in every document to aggregate properties. The only value allowed now is ["sourceFile", "metadata"]. It means to aggregate only metadata properties (aka keys).
query (str | None): The free text search query, for details see the documentation referenced above.
filter (Filter | dict[str, Any] | None): The filter to narrow down the documents to count cardinality.
aggregate_filter (AggregationFilter | dict[str, Any] | None): The filter to apply to the resulting buckets.
Expand All @@ -354,9 +354,8 @@ def aggregate_cardinality_properties(
Count the number metadata keys for documents in your CDF project:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes.documents import SourceFileProperty
>>> client = CogniteClient()
>>> count = client.documents.aggregate_cardinality_properties(SourceFileProperty.metadata)
>>> count = client.documents.aggregate_cardinality_properties()
"""
self._validate_filter(filter)

Expand Down
14 changes: 6 additions & 8 deletions cognite/client/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@

T = TypeVar("T", bound=CogniteObject)

VALID_AGGREGATIONS = {"count", "cardinalityValues", "cardinalityProperties", "uniqueValues", "uniqueProperties"}


class APIClient:
_RESOURCE_PATH: str
Expand Down Expand Up @@ -787,24 +789,22 @@ def _advanced_aggregate(
api_subversion: str | None = None,
) -> int | UniqueResultList:
verify_limit(limit)
if aggregate not in ["count", "cardinalityValues", "cardinalityProperties", "uniqueValues", "uniqueProperties"]:
raise ValueError(
f"Invalid aggregate '{aggregate}'. Valid aggregates are 'count', 'cardinalityValues', "
f"'cardinalityProperties', 'uniqueValues', and 'uniqueProperties'."
)
if aggregate not in VALID_AGGREGATIONS:
raise ValueError(f"Invalid aggregate {aggregate!r}. Valid aggregates are {sorted(VALID_AGGREGATIONS)}.")

body: dict[str, Any] = {"aggregate": aggregate}
if properties is not None:
if isinstance(properties, tuple):
properties, property_aggregation_filter = properties
else:
property_aggregation_filter = None

if isinstance(properties, EnumProperty):
dumped_properties = properties.as_reference()
elif isinstance(properties, str):
dumped_properties = [to_camel_case(properties)]
elif isinstance(properties, list):
dumped_properties = [to_camel_case(p) for p in properties]
dumped_properties = [to_camel_case(properties[0])] if len(properties) == 1 else properties
else:
raise ValueError(f"Unknown property format: {properties}")

Expand Down Expand Up @@ -832,8 +832,6 @@ def _advanced_aggregate(
dumped_filter = filter.dump(camel_case=True)
elif isinstance(filter, dict):
dumped_filter = convert_all_keys_to_camel_case(filter)
else:
raise ValueError(f"Unknown filter format: {filter}")
body["filter"] = dumped_filter

if advanced_filter is not None:
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

__version__ = "7.70.2"
__version__ = "7.70.3"

__api_subversion__ = "20230101"
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 = "7.70.2"
version = "7.70.3"

description = "Cognite Python SDK"
readme = "README.md"
Expand Down
Loading
Loading