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

TimeSeries and TimeSeriesEvent constructor should accept an object to construct from #199

Closed
felixchenier opened this issue Nov 8, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@felixchenier
Copy link
Collaborator

felixchenier commented Nov 8, 2023

At the moment, we can only construct an empty TimeSeries:

ts = TimeSeries()

or a TimeSeries with given attributes:

ts = TimeSeries(time=time, data=data, ...)

We can't construct a TimeSeries based on another object:

ts = TimeSeries(array)
ts = TimeSeries(dataframe)  <-- we can using ts = TimeSeries.from_dataframe(dataframe)
ts = TimeSeries(list)
ts = TimeSeries(series)
ts = TimeSeries(dict_of_arrays)

All these contructs should be accepted and lead to a TimeSeries, with a matched time attribute, which will allow to typecast lots of types to TimeSeries and therefore will simplify compatibility with other Python tools.

breaking compatibility

This would lead to a compatibility break in some (maybe fictitious) cases where someone initialized a TimeSeries using a list of arguments rather than keyword arguments, because the init signature would move from:

def __init__(
        self,
        time: np.ndarray = np.array([]),
        time_info: dict[str, Any] = {"Unit": "s"},
        data: dict[str, np.ndarray] = {},
        data_info: dict[str, dict[str, Any]] = {},
        events: list[TimeSeriesEvent] = [],
    )

to:

def __init__(
        self,
        source: TimeSeries | pd.DataFrame | pd.Series | ArrayLike,
        *,
        time: np.ndarray = np.array([]),
        time_info: dict[str, Any] = {"Unit": "s"},
        data: dict[str, np.ndarray] = {},
        data_info: dict[str, dict[str, Any]] = {},
        events: list[TimeSeriesEvent] = [],
    )

I think this is easy to solve in existing code, and it brings a lot of value.

@felixchenier felixchenier added the enhancement New feature or request label Nov 8, 2023
@felixchenier felixchenier added this to the 1.0 milestone Nov 8, 2023
@felixchenier felixchenier self-assigned this Nov 8, 2023
@felixchenier felixchenier modified the milestones: 1.0, 0.14 Nov 10, 2023
felixchenier added a commit that referenced this issue Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant