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

Use numpy arrays in time series #55

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

daniel-thom
Copy link
Collaborator

@daniel-thom daniel-thom commented Nov 15, 2024

We were previously storing time series arrays as pyarrow arrays. That was causing complexity because users often need numpy arrays. The team decided to convert them to numpy arrays straightaway instead.

I also upgraded mypy and fixed some errors caused by that upgrade.

Fixes #54

"""Check time series data."""
if len(data) < 2:
msg = f"SingleTimeSeries length must be at least 2: {len(data)}"
raise ValueError(msg)

if isinstance(data, pint.Quantity):
if not isinstance(data.magnitude, np.ndarray):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please confirm that this is correct. Previously, if the user passed a range object inside a pint Quantity, pint would leave it alone. This guarantees that SingleTimeSeries will always have numpy array.

@@ -341,7 +352,7 @@ def from_data(cls, time_series: SingleTimeSeries, **user_attributes) -> Any:
quantity_type=type(time_series.data),
units=str(time_series.data.units),
)
if isinstance(time_series.data, BaseQuantity)
if isinstance(time_series.data, pint.Quantity)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pesap This fixes the Quantity vs BaseQuantity issue.

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 92.95775% with 5 lines in your changes missing coverage. Please review.

Project coverage is 95.04%. Comparing base (169accf) to head (00c9dfe).

Files with missing lines Patch % Lines
src/infrasys/time_series_models.py 78.26% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #55      +/-   ##
==========================================
- Coverage   95.24%   95.04%   -0.21%     
==========================================
  Files          33       33              
  Lines        2778     2807      +29     
==========================================
+ Hits         2646     2668      +22     
- Misses        132      139       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@daniel-thom daniel-thom merged commit f3703dd into main Nov 18, 2024
6 checks passed
@daniel-thom daniel-thom deleted the fix/time-series-as-numpy branch November 18, 2024 19:34
github-actions bot pushed a commit that referenced this pull request Nov 18, 2024
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.

Time series drop units of pint.Quantitys that do not subclass infrasys.BaseQuantity
3 participants