diff --git a/cognite/client/_api/assets.py b/cognite/client/_api/assets.py index 63526108be..6f75735787 100644 --- a/cognite/client/_api/assets.py +++ b/cognite/client/_api/assets.py @@ -296,10 +296,10 @@ def aggregate_count( Count the number of assets with the metadata key "timezone" in your CDF project: >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes.filters import ContainsAny >>> from cognite.client.data_classes.assets import AssetProperty >>> c = CogniteClient() - >>> has_timezone = filters.ContainsAny(AssetProperty.metadata, "timezone") + >>> has_timezone = ContainsAny(AssetProperty.metadata, "timezone") >>> asset_count = c.assets.aggregate_count(advanced_filter=has_timezone) """ @@ -340,11 +340,13 @@ def aggregate_cardinality_values( Count the number of timezones (metadata key) for assets with the word "critical" in the description in your CDF project: >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes.filters import Search >>> from cognite.client.data_classes.assets import AssetProperty >>> c = CogniteClient() - >>> is_critical = filters.Search(AssetProperty.description, "critical") - >>> critical_assets = c.assets.aggregate_cardinality_values(AssetProperty.metadata_key("timezone"), advanced_filter=is_critical) + >>> is_critical = Search(AssetProperty.description, "critical") + >>> critical_assets = c.assets.aggregate_cardinality_values( + ... AssetProperty.metadata_key("timezone"), + ... advanced_filter=is_critical) """ self._validate_filter(advanced_filter) return self._advanced_aggregate( @@ -425,12 +427,12 @@ def aggregate_unique_values( Get the different labels with count used for assets created after 2020-01-01 in your CDF project: >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes import filters as flt >>> from cognite.client.data_classes.assets import AssetProperty >>> from cognite.client.utils import timestamp_to_ms >>> from datetime import datetime >>> c = CogniteClient() - >>> created_after_2020 = filters.Range(AssetProperty.created_time, gte=timestamp_to_ms(datetime(2020, 1, 1))) + >>> created_after_2020 = flt.Range(AssetProperty.created_time, gte=timestamp_to_ms(datetime(2020, 1, 1))) >>> result = c.assets.aggregate_unique_values(AssetProperty.labels, advanced_filter=created_after_2020) >>> print(result.unique) @@ -439,10 +441,11 @@ def aggregate_unique_values( >>> from cognite.client import CogniteClient >>> from cognite.client.data_classes.assets import AssetProperty - >>> from cognite.client.data_classes import aggregations as aggs, filters + >>> from cognite.client.data_classes import aggregations as aggs + >>> from cognite.client.data_classes import filters as flt >>> c = CogniteClient() >>> not_test = aggs.Not(aggs.Prefix("test")) - >>> created_after_2020 = filters.Range(AssetProperty.last_updated_time, gte=timestamp_to_ms(datetime(2020, 1, 1))) + >>> created_after_2020 = flt.Range(AssetProperty.last_updated_time, gte=timestamp_to_ms(datetime(2020, 1, 1))) >>> result = c.assets.aggregate_unique_values(AssetProperty.labels, advanced_filter=created_after_2020, aggregate_filter=not_test) >>> print(result.unique) @@ -839,12 +842,10 @@ def filter( and sort by external id ascending: >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes import filters as flt >>> c = CogniteClient() - >>> f = filters - >>> in_timezone = f.Prefix(["metadata", "timezone"], "Europe") - >>> res = c.assets.filter(filter=in_timezone, - ... sort=("external_id", "asc")) + >>> in_timezone = flt.Prefix(["metadata", "timezone"], "Europe") + >>> res = c.assets.filter(filter=in_timezone, sort=("external_id", "asc")) Note that you can check the API documentation above to see which properties you can filter on with which filters. @@ -853,13 +854,13 @@ def filter( for filtering and sorting, you can also use the `AssetProperty` and `SortableAssetProperty` Enums. >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes import filters as flt >>> from cognite.client.data_classes.assets import AssetProperty, SortableAssetProperty >>> c = CogniteClient() - >>> f = filters - >>> in_timezone = f.Prefix(AssetProperty.metadata_key("timezone"), "Europe") - >>> res = c.assets.filter(filter=in_timezone, - ... sort=(SortableAssetProperty.external_id, "asc")) + >>> in_timezone = flt.Prefix(AssetProperty.metadata_key("timezone"), "Europe") + >>> res = c.assets.filter( + ... filter=in_timezone, + ... sort=(SortableAssetProperty.external_id, "asc")) """ self._validate_filter(filter) diff --git a/cognite/client/_api/datapoints_subscriptions.py b/cognite/client/_api/datapoints_subscriptions.py index 04b1a3c00e..4eb602e6ff 100644 --- a/cognite/client/_api/datapoints_subscriptions.py +++ b/cognite/client/_api/datapoints_subscriptions.py @@ -57,13 +57,16 @@ def create(self, subscription: DataPointSubscriptionCreate) -> DatapointSubscrip >>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import DataPointSubscriptionCreate - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes import filters as flt >>> from cognite.client.data_classes.datapoints_subscriptions import DatapointSubscriptionFilterProperties >>> c = CogniteClient() - >>> f = filters - >>> p = DatapointSubscriptionFilterProperties - >>> numeric_timeseries = f.Equals(p.is_string, False) - >>> sub = DataPointSubscriptionCreate("mySubscription", partition_count=1, filter=numeric_timeseries, name="My subscription for Numeric time series") + >>> prop = DatapointSubscriptionFilterProperties.is_string + >>> numeric_timeseries = flt.Equals(prop, False) + >>> sub = DataPointSubscriptionCreate( + ... "mySubscription", + ... partition_count=1, + ... filter=numeric_timeseries, + ... name="My subscription for Numeric time series") >>> created = c.time_series.subscriptions.create(sub) """ self._warning.warn() diff --git a/cognite/client/_api/events.py b/cognite/client/_api/events.py index 0e11625bbd..3f932d9437 100644 --- a/cognite/client/_api/events.py +++ b/cognite/client/_api/events.py @@ -643,13 +643,12 @@ def filter( and sort by start time descending: >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes import filters as flt >>> c = CogniteClient() - >>> f = filters - >>> is_workorder = f.Prefix("external_id", "workorder") - >>> has_failure = f.Search("description", "failure") - >>> res = c.events.filter(filter=f.And(is_workorder, has_failure), - ... sort=("start_time", "desc")) + >>> is_workorder = flt.Prefix("external_id", "workorder") + >>> has_failure = flt.Search("description", "failure") + >>> res = c.events.filter( + ... filter=flt.And(is_workorder, has_failure), sort=("start_time", "desc")) Note that you can check the API documentation above to see which properties you can filter on with which filters. @@ -658,14 +657,14 @@ def filter( for filtering and sorting, you can also use the `EventProperty` and `SortableEventProperty` enums. >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes import filters as flt >>> from cognite.client.data_classes.events import EventProperty, SortableEventProperty >>> c = CogniteClient() - >>> f = filters - >>> is_workorder = f.Prefix(EventProperty.external_id, "workorder") - >>> has_failure = f.Search(EventProperty.description, "failure") - >>> res = c.events.filter(filter=f.And(is_workorder, has_failure), - ... sort=(SortableEventProperty.start_time, "desc")) + >>> is_workorder = flt.Prefix(EventProperty.external_id, "workorder") + >>> has_failure = flt.Search(EventProperty.description, "failure") + >>> res = c.events.filter( + ... filter=flt.And(is_workorder, has_failure), + ... sort=(SortableEventProperty.start_time, "desc")) """ self._validate_filter(filter) diff --git a/cognite/client/_api/sequences.py b/cognite/client/_api/sequences.py index a9d8319667..049eb1bd2f 100644 --- a/cognite/client/_api/sequences.py +++ b/cognite/client/_api/sequences.py @@ -732,12 +732,11 @@ def filter( return them sorted by created time: >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes import filters as flt >>> c = CogniteClient() - >>> f = filters - >>> is_asset = f.Equals("asset_id", 123) - >>> is_efficiency = f.Equals(["metadata", "type"], "efficiency") - >>> res = c.time_series.filter(filter=f.And(is_asset, is_efficiency), sort="created_time") + >>> asset_filter = flt.Equals("asset_id", 123) + >>> is_efficiency = flt.Equals(["metadata", "type"], "efficiency") + >>> res = c.time_series.filter(filter=flt.And(asset_filter, is_efficiency), sort="created_time") Note that you can check the API documentation above to see which properties you can filter on with which filters. @@ -746,14 +745,14 @@ def filter( for filtering and sorting, you can also use the `SequenceProperty` and `SortableSequenceProperty` enums. >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes import filters as flt >>> from cognite.client.data_classes.sequences import SequenceProperty, SortableSequenceProperty >>> c = CogniteClient() - >>> f = filters - >>> is_asset = f.Equals(SequenceProperty.asset_id, 123) - >>> is_efficiency = f.Equals(SequenceProperty.metadata_key("type"), "efficiency") - >>> res = c.time_series.filter(filter=f.And(is_asset, is_efficiency), - ... sort=SortableSequenceProperty.created_time) + >>> asset_filter = flt.Equals(SequenceProperty.asset_id, 123) + >>> is_efficiency = flt.Equals(SequenceProperty.metadata_key("type"), "efficiency") + >>> res = c.time_series.filter( + ... filter=flt.And(asset_filter, is_efficiency), + ... sort=SortableSequenceProperty.created_time) """ self._validate_filter(filter) diff --git a/cognite/client/_api/time_series.py b/cognite/client/_api/time_series.py index 093239d11a..5bbcb0f395 100644 --- a/cognite/client/_api/time_series.py +++ b/cognite/client/_api/time_series.py @@ -728,10 +728,9 @@ def filter( Find all numeric time series and return them sorted by external id: >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes.filters import Equals >>> c = CogniteClient() - >>> f = filters - >>> is_numeric = f.Equals("is_string", False) + >>> is_numeric = Equals("is_string", False) >>> res = c.time_series.filter(filter=is_numeric, sort="external_id") Note that you can check the API documentation above to see which properties you can filter on @@ -741,11 +740,10 @@ def filter( for filtering and sorting, you can also use the `TimeSeriesProperty` and `SortableTimeSeriesProperty` enums. >>> from cognite.client import CogniteClient - >>> from cognite.client.data_classes import filters + >>> from cognite.client.data_classes.filters import Equals >>> from cognite.client.data_classes.time_series import TimeSeriesProperty, SortableTimeSeriesProperty >>> c = CogniteClient() - >>> f = filters - >>> is_numeric = f.Equals(TimeSeriesProperty.is_string, False) + >>> is_numeric = Equals(TimeSeriesProperty.is_string, False) >>> res = c.time_series.filter(filter=is_numeric, sort=SortableTimeSeriesProperty.external_id) """ self._validate_filter(filter)