Repository navigation
python(fix): return run bounds as nanosecond timestamps #857
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec5fb7f
python(fix): return run bounds as nanosecond timestamps
ian-sift 1f68928
python(chore): name the changelog fragment after the pull request
ian-sift b579acf
python(fix): compare run bounds with the channel timestamp index
ian-sift b4e251c
python(fix): narrow the channel index to a DatetimeIndex
ian-sift ed82892
python(fix): return annotation, step, and import bounds as nanosecond…
ian-sift 899d3e8
python(fix): read channel index integers without DatetimeIndex.asi8
ian-sift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Run, annotation, test step, and data import time bounds are nanosecond timestamps, matching channel data, so a time axis built from them lines up with `get_data`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """Shared check that a time axis matches the index ``get_data`` builds.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| from google.protobuf.any_pb2 import Any | ||
| from sift.common.type.v1.channel_data_type_pb2 import CHANNEL_DATA_TYPE_DOUBLE | ||
| from sift.data.v2.data_pb2 import DoubleValue, DoubleValues, Metadata | ||
|
|
||
| from sift_client._internal.low_level_wrappers.data import DataLowLevelClient | ||
|
|
||
| if TYPE_CHECKING: | ||
| from google.protobuf.timestamp_pb2 import Timestamp | ||
|
|
||
|
|
||
| def channel_index(*timestamps: Timestamp) -> pd.DatetimeIndex: | ||
| """Index ``get_data`` builds for double-channel samples at these times.""" | ||
| values = DoubleValues( | ||
| metadata=Metadata( | ||
| data_type=CHANNEL_DATA_TYPE_DOUBLE, | ||
| sampled_ms=0, | ||
| channel=Metadata.Channel(name="voltage"), | ||
| ), | ||
| values=[DoubleValue(timestamp=ts, value=1.0) for ts in timestamps], | ||
| ) | ||
| packed = Any() | ||
| packed.Pack(values) | ||
| # ``Pack`` writes ``type.googleapis.com/...``. The data parser reads the | ||
| # ``sift.data`` prefix the API sends. | ||
| packed.type_url = "sift.data.v2.DoubleValues" | ||
| frame = DataLowLevelClient.try_deserialize_channel_data(packed)["voltage"] | ||
| index = frame.index | ||
| assert isinstance(index, pd.DatetimeIndex) | ||
| return index | ||
|
|
||
|
|
||
| def _integer_view(index: pd.DatetimeIndex) -> list[int]: | ||
| """Integers in the index's own unit, the scale interpolation uses.""" | ||
| return [int(value) for value in np.asarray(index, dtype=np.int64)] | ||
|
|
||
|
|
||
| def assert_axis_matches_channel(start, stop, *timestamps: Timestamp) -> None: | ||
| """A ``date_range`` across these bounds uses the channel index scale.""" | ||
| samples = channel_index(*timestamps) | ||
| axis = pd.date_range(start, stop, periods=2) | ||
| assert str(samples.dtype).startswith("datetime64[ns") | ||
| assert axis.dtype == samples.dtype | ||
| assert _integer_view(axis) == _integer_view(samples) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.