Skip to content

Commit

Permalink
refactor: regen
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino committed Jan 31, 2025
1 parent 63bb518 commit 337c362
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 241 deletions.
42 changes: 0 additions & 42 deletions examples/cognite_core/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def upsert(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
allow_version_increase: bool = False,
) -> data_classes.ResourcesWriteResult:
"""Add or update (upsert) items.
Expand All @@ -122,9 +121,6 @@ def upsert(
matching and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing values (false)?
Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None.
However, if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
allow_version_increase (bool): If set to true, the version of the instance will be increased
if the instance already exists.
If you get an error: 'A version conflict caused the ingest to fail', you can set this to true to allow
Expand All @@ -133,14 +129,6 @@ def upsert(
Created instance(s), i.e., nodes, edges, and time series.
"""
if write_none is True:
warnings.warn(
"The write_none argument is deprecated and will be removed in v1.0. "
"Setting it has no effect. Instead, pygen will detect properties "
"that are explicitly set to None and write them.",
UserWarning,
stacklevel=2,
)
instances = self._create_instances(items, allow_version_increase)
result = self._client.data_modeling.instances.apply(
nodes=instances.nodes,
Expand Down Expand Up @@ -183,36 +171,6 @@ def _create_instances(
)
return instances

def apply(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
) -> data_classes.ResourcesWriteResult:
"""[DEPRECATED] Add or update (upsert) items.
Args:
items: One or more instances of the pygen generated data classes.
replace (bool): How do we behave when a property value exists? Do we replace all
matching and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing
values (false)? Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None.
However, if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
Returns:
Created instance(s), i.e., nodes, edges, and time series.
"""
warnings.warn(
"The .apply method is deprecated and will be removed in v1.0. "
"Please use the .upsert method on the instead."
"The motivation is that .upsert is a more descriptive name for the operation.",
UserWarning,
stacklevel=2,
)
return self.upsert(items, replace, write_none)

def delete(
self,
external_id: (
Expand Down
42 changes: 0 additions & 42 deletions examples/omni/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def upsert(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
allow_version_increase: bool = False,
) -> data_classes.ResourcesWriteResult:
"""Add or update (upsert) items.
Expand All @@ -104,9 +103,6 @@ def upsert(
matching and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing values (false)?
Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None.
However, if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
allow_version_increase (bool): If set to true, the version of the instance will be increased
if the instance already exists.
If you get an error: 'A version conflict caused the ingest to fail', you can set this to true to allow
Expand All @@ -115,14 +111,6 @@ def upsert(
Created instance(s), i.e., nodes, edges, and time series.
"""
if write_none is True:
warnings.warn(
"The write_none argument is deprecated and will be removed in v1.0. "
"Setting it has no effect. Instead, pygen will detect properties "
"that are explicitly set to None and write them.",
UserWarning,
stacklevel=2,
)
instances = self._create_instances(items, allow_version_increase)
result = self._client.data_modeling.instances.apply(
nodes=instances.nodes,
Expand Down Expand Up @@ -165,36 +153,6 @@ def _create_instances(
)
return instances

def apply(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
) -> data_classes.ResourcesWriteResult:
"""[DEPRECATED] Add or update (upsert) items.
Args:
items: One or more instances of the pygen generated data classes.
replace (bool): How do we behave when a property value exists? Do we replace all
matching and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing
values (false)? Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None.
However, if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
Returns:
Created instance(s), i.e., nodes, edges, and time series.
"""
warnings.warn(
"The .apply method is deprecated and will be removed in v1.0. "
"Please use the .upsert method on the instead."
"The motivation is that .upsert is a more descriptive name for the operation.",
UserWarning,
stacklevel=2,
)
return self.upsert(items, replace, write_none)

def delete(
self,
external_id: (
Expand Down
42 changes: 0 additions & 42 deletions examples/omni_multi/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def upsert(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
allow_version_increase: bool = False,
) -> data_classes.ResourcesWriteResult:
"""Add or update (upsert) items.
Expand All @@ -152,9 +151,6 @@ def upsert(
existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing values (false)?
Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None. However,
if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
allow_version_increase (bool): If set to true, the version of the instance will be increased
if the instance already exists.
If you get an error: 'A version conflict caused the ingest to fail', you can set this to true to allow
Expand All @@ -163,14 +159,6 @@ def upsert(
Created instance(s), i.e., nodes, edges, and time series.
"""
if write_none is True:
warnings.warn(
"The write_none argument is deprecated and will be removed in v1.0. "
"Setting it has no effect. Instead, pygen will detect properties "
"that are explicitly set to None and write them.",
UserWarning,
stacklevel=2,
)
instances = self._create_instances(items, allow_version_increase)
result = self._client.data_modeling.instances.apply(
nodes=instances.nodes,
Expand Down Expand Up @@ -213,36 +201,6 @@ def _create_instances(
)
return instances

def apply(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
) -> data_classes.ResourcesWriteResult:
"""[DEPRECATED] Add or update (upsert) items.
Args:
items: One or more instances of the pygen generated data classes.
replace (bool): How do we behave when a property value exists? Do we replace all matching
and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing values (false)?
Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None. However,
if you want to set properties to None, you can set this parameter to True. Note this
only applies to properties that are nullable.
Returns:
Created instance(s), i.e., nodes, edges, and time series.
"""
warnings.warn(
"The .apply method is deprecated and will be removed in v1.0. "
"Please use the .upsert method on the instead."
"The motivation is that .upsert is a more descriptive name for the operation.",
UserWarning,
stacklevel=2,
)
return self.upsert(items, replace, write_none)

def delete(
self,
external_id: (
Expand Down
42 changes: 0 additions & 42 deletions examples/omni_sub/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def upsert(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
allow_version_increase: bool = False,
) -> data_classes.ResourcesWriteResult:
"""Add or update (upsert) items.
Expand All @@ -68,9 +67,6 @@ def upsert(
matching and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing values (false)?
Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None.
However, if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
allow_version_increase (bool): If set to true, the version of the instance will be increased
if the instance already exists.
If you get an error: 'A version conflict caused the ingest to fail', you can set this to true to allow
Expand All @@ -79,14 +75,6 @@ def upsert(
Created instance(s), i.e., nodes, edges, and time series.
"""
if write_none is True:
warnings.warn(
"The write_none argument is deprecated and will be removed in v1.0. "
"Setting it has no effect. Instead, pygen will detect properties "
"that are explicitly set to None and write them.",
UserWarning,
stacklevel=2,
)
instances = self._create_instances(items, allow_version_increase)
result = self._client.data_modeling.instances.apply(
nodes=instances.nodes,
Expand Down Expand Up @@ -129,36 +117,6 @@ def _create_instances(
)
return instances

def apply(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
) -> data_classes.ResourcesWriteResult:
"""[DEPRECATED] Add or update (upsert) items.
Args:
items: One or more instances of the pygen generated data classes.
replace (bool): How do we behave when a property value exists? Do we replace all
matching and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing
values (false)? Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None.
However, if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
Returns:
Created instance(s), i.e., nodes, edges, and time series.
"""
warnings.warn(
"The .apply method is deprecated and will be removed in v1.0. "
"Please use the .upsert method on the instead."
"The motivation is that .upsert is a more descriptive name for the operation.",
UserWarning,
stacklevel=2,
)
return self.upsert(items, replace, write_none)

def delete(
self,
external_id: (
Expand Down
42 changes: 0 additions & 42 deletions examples/wind_turbine/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def upsert(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
allow_version_increase: bool = False,
) -> data_classes.ResourcesWriteResult:
"""Add or update (upsert) items.
Expand All @@ -92,9 +91,6 @@ def upsert(
matching and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing values (false)?
Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None.
However, if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
allow_version_increase (bool): If set to true, the version of the instance will be increased
if the instance already exists.
If you get an error: 'A version conflict caused the ingest to fail', you can set this to true to allow
Expand All @@ -103,14 +99,6 @@ def upsert(
Created instance(s), i.e., nodes, edges, and time series.
"""
if write_none is True:
warnings.warn(
"The write_none argument is deprecated and will be removed in v1.0. "
"Setting it has no effect. Instead, pygen will detect properties "
"that are explicitly set to None and write them.",
UserWarning,
stacklevel=2,
)
instances = self._create_instances(items, allow_version_increase)
result = self._client.data_modeling.instances.apply(
nodes=instances.nodes,
Expand Down Expand Up @@ -153,36 +141,6 @@ def _create_instances(
)
return instances

def apply(
self,
items: data_classes.DomainModelWrite | Sequence[data_classes.DomainModelWrite],
replace: bool = False,
write_none: bool = False,
) -> data_classes.ResourcesWriteResult:
"""[DEPRECATED] Add or update (upsert) items.
Args:
items: One or more instances of the pygen generated data classes.
replace (bool): How do we behave when a property value exists? Do we replace all
matching and existing values with the supplied values (true)?
Or should we merge in new values for properties together with the existing
values (false)? Note: This setting applies for all nodes or edges specified in the ingestion call.
write_none (bool): This method will, by default, skip properties that are set to None.
However, if you want to set properties to None,
you can set this parameter to True. Note this only applies to properties that are nullable.
Returns:
Created instance(s), i.e., nodes, edges, and time series.
"""
warnings.warn(
"The .apply method is deprecated and will be removed in v1.0. "
"Please use the .upsert method on the instead."
"The motivation is that .upsert is a more descriptive name for the operation.",
UserWarning,
stacklevel=2,
)
return self.upsert(items, replace, write_none)

def delete(
self,
external_id: (
Expand Down
32 changes: 1 addition & 31 deletions tests/test_integration/test_upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,43 +174,13 @@ def primitive_nullable_node(
cognite_client.data_modeling.instances.delete(nodes=node.as_tuple_id())


def test_update_to_null(
omni_client: OmniClient, cognite_client: CogniteClient, primitive_nullable_node: dc.PrimitiveNullableApply
) -> None:
update = primitive_nullable_node.model_copy()

update.text = None
update.int_32 = None
update.int_64 = None
update.float_32 = None
update.float_64 = None
update.boolean = None
update.timestamp = None
update.date = None
update.json_ = None

omni_client.upsert(update, write_none=True)

retrieved = omni_client.primitive_nullable.retrieve(primitive_nullable_node.external_id)
assert retrieved is not None
assert retrieved.text is None
assert retrieved.int_32 is None
assert retrieved.int_64 is None
assert retrieved.float_32 is None
assert retrieved.float_64 is None
assert retrieved.boolean is None
assert retrieved.timestamp is None
assert retrieved.date is None
assert retrieved.json_ is None


def test_set_empty_string(
omni_client: OmniClient, cognite_client: CogniteClient, primitive_nullable_node: dc.PrimitiveNullableApply
) -> None:
update = primitive_nullable_node.model_copy()

update.text = ""
omni_client.upsert(update, write_none=True)
omni_client.upsert(update)
retrieved = omni_client.primitive_nullable.retrieve(primitive_nullable_node.external_id)
assert retrieved is not None, f"Node {primitive_nullable_node.external_id} not found"
assert retrieved.text == ""
Expand Down

0 comments on commit 337c362

Please sign in to comment.