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

InstanceId TimeSeries #1825

Merged
merged 27 commits into from
Jun 26, 2024
Merged

InstanceId TimeSeries #1825

merged 27 commits into from
Jun 26, 2024

Conversation

doctrino
Copy link
Contributor

Description

Please describe the change you have made.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

@doctrino doctrino marked this pull request as ready for review June 21, 2024 19:54
@doctrino doctrino requested review from a team as code owners June 21, 2024 19:54
@doctrino doctrino requested review from roligheten and removed request for a team June 21, 2024 19:54
@@ -31,6 +31,6 @@ runs:
- name: Install dependencies
shell: bash
run: |
pip install --upgrade pip poetry
python -m pip install --upgrade pip poetry
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Windows failed without this one

@@ -87,43 +90,26 @@ def load(


@dataclass(frozen=True)
class InstanceId:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to avoid circular import.

Copy link

codecov bot commented Jun 21, 2024

Codecov Report

Attention: Patch coverage is 79.31034% with 30 lines in your changes missing coverage. Please review.

Project coverage is 92.73%. Comparing base (6686e3b) to head (8fe3752).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1825      +/-   ##
==========================================
- Coverage   92.80%   92.73%   -0.07%     
==========================================
  Files         121      121              
  Lines       17871    17950      +79     
==========================================
+ Hits        16585    16646      +61     
- Misses       1286     1304      +18     
Files Coverage Δ
cognite/client/_version.py 100.00% <100.00%> (ø)
cognite/client/data_classes/datapoints.py 91.79% <100.00%> (+0.07%) ⬆️
cognite/client/utils/_validation.py 100.00% <100.00%> (ø)
cognite/client/_api/datapoint_tasks.py 94.97% <80.00%> (-0.12%) ⬇️
cognite/client/data_classes/data_modeling/ids.py 92.56% <58.33%> (-1.74%) ⬇️
cognite/client/utils/_identifier.py 90.45% <81.66%> (-2.88%) ⬇️
cognite/client/_api/datapoints.py 96.43% <75.47%> (-1.94%) ⬇️

... and 4 files with indirect coverage changes

Comment on lines 1491 to 1494
if "instance_id" in d and isinstance(d["instance_id"], InstanceId):
d["instance_id"] = d["instance_id"].dump(include_instance_type=False) # type: ignore[assignment]
elif "instanceId" in d and isinstance(d["instanceId"], InstanceId):
d["instanceId"] = d["instanceId"].dump(include_instance_type=False) # type: ignore[assignment]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why handle both instance_id and instanceId? I say just use the camelCased version. I find that it's easier for both users and developers when there's only one way to do a particular thing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also seems like this logic rather should live in _verify_and_prepare_dps_objects

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it is not necessary. It is already handled in _verify_and_prepare_dps_objects 🤦

Comment on lines 1679 to 1686
elif (instance_id := validated.get("instanceId")) is not None:
dps_to_insert["instanceId", (instance_id["space"], instance_id["externalId"])].extend(validated_dps)
else:
dps_to_insert["id", validated["id"]].extend(validated_dps)
return list(dps_to_insert.items())
return [
((id_name, {"space": id_[0], "externalId": id_[1]} if id_name == "instanceId" else id_), data) # type: ignore[index, misc]
for (id_name, id_), data in dps_to_insert.items()
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you're transforming from a dict to a tuple and then back to a dict - presumably because the dict is not hashable? Might require less back-and-forth and be simpler if validate_user_input_dict_with_identifier returns Identifier objects - which should be hashable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, simplified it. Note sure what made me go for this complex solution.

cognite/client/_api/datapoints.py Outdated Show resolved Hide resolved
cognite/client/_api/datapoints.py Outdated Show resolved Hide resolved
cognite/client/_api/datapoints.py Outdated Show resolved Hide resolved
cognite/client/data_classes/datapoints.py Outdated Show resolved Hide resolved
cognite/client/data_classes/datapoints.py Outdated Show resolved Hide resolved
cognite/client/data_classes/datapoints.py Outdated Show resolved Hide resolved
cognite/client/data_classes/datapoints.py Outdated Show resolved Hide resolved
# Conflicts:
#	CHANGELOG.md
#	cognite/client/_version.py
#	pyproject.toml
@erlendvollset erlendvollset force-pushed the instance-id-timeseries branch 3 times, most recently from ab65281 to 3878f0b Compare June 26, 2024 11:32
@doctrino doctrino merged commit 13b10e7 into master Jun 26, 2024
14 checks passed
@doctrino doctrino deleted the instance-id-timeseries branch June 26, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants