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

added aggrgate_type argument in aggregate class method for SingleTime… #52

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

KapilDuwadi
Copy link
Collaborator

…Series

@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 79.54545% with 9 lines in your changes missing coverage. Please review.

Project coverage is 95.02%. Comparing base (169accf) to head (d87d9d1).

Files with missing lines Patch % Lines
src/infrasys/time_series_models.py 67.85% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #52      +/-   ##
==========================================
- Coverage   95.24%   95.02%   -0.23%     
==========================================
  Files          33       33              
  Lines        2778     2815      +37     
==========================================
+ Hits         2646     2675      +29     
- Misses        132      140       +8     

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

@KapilDuwadi KapilDuwadi linked an issue Nov 13, 2024 that may be closed by this pull request
@KapilDuwadi
Copy link
Collaborator Author

KapilDuwadi commented Nov 13, 2024

@daniel-thom or @pesap Could you review this ?

@@ -102,7 +102,7 @@ def check_data(
return data

@classmethod
def aggregate(cls, ts_data: list[Self]) -> Self:
def aggregate(cls, ts_data: list[Self], agg_type: Literal["sum", "avg"] = "sum") -> Self:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should explore to have this method as a standalone function. It feels unnatural to me that we define a method that can take multiple instances of itself. I am open for discussion.

@@ -102,7 +102,7 @@ def check_data(
return data

@classmethod
def aggregate(cls, ts_data: list[Self]) -> Self:
def aggregate(cls, ts_data: list[Self], agg_type: Literal["sum", "avg"] = "sum") -> Self:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the convention we have is to return "SingleTimeSeries" instead of self

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's what I thought at first also. However, https://peps.python.org/pep-0673/#use-in-classmethod-signatures

@@ -119,7 +119,7 @@ def aggregate(cls, ts_data: list[Self]) -> Self:
InconsistentTimeseriesAggregation
Raised if incompatible timeseries data are passed.
"""

agg_func = {"sum": sum, "avg": lambda x: sum(x) / len(x)}[agg_type]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Peaky detail, but I am not a fam of defining functions inside functions. We can define this methods outside maybe?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, wouldn't it be more consistent if we use numpy functions?

if issubclass(magnitude_type, pa.Array):
new_data = sum(
if issubclass(magnitude_type, pa.Array) and is_quantity:
new_data = agg_func(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could simply this cases. In all
the instances you have array and if it is pa.array we just need to convert it to numpy.

@@ -264,6 +263,38 @@ def from_time_array(
def get_time_series_metadata_type() -> Type:
return SingleTimeSeriesMetadata

# Support for scalar * SingleTimeSeries
def __mul__(self, scalar: int | float | BaseQuantity) -> Self:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I personally do not like this. Do we really need this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants