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 a specific value for the default when not given (e.g. NotGiven) to differentiate a default=None with a default not given #279

Open
sdementen opened this issue Mar 15, 2024 · 2 comments

Comments

@sdementen
Copy link
Contributor

No description provided.

@stringertheory
Copy link
Owner

@sdementen thanks for adding this (and the handful of other issues you added)!

Are you thinking that default=NotGiven should be used in the TimeSeries constructor? Or is this related to operations on a TimeSeries that return a new TimeSeries (for example like it's currently used in the to_bool method)?

In general I agree that default values need to be handled more consistently than they currently are, maybe even changing default away from being a keyword argument in the TimeSeries constructor to make it more explicit.

My current thinking is that it makes sense to have default=NotGiven when there are operations that return a new TimeSeries, and a default needs to be set on the result. In those cases, passing "NotGiven" means "make an educated guess" about the default value of the new TimeSeries, but passing in any value (including None) allows users to explicitly set the default value of the resulting TimeSeries. That pattern wouldn't translate to the constructor of the TimeSeries itself, though (because basically the "educated guess" is that the default value is None, so it can just be used directly).

Would love to hear what you think makes the most sense!

@sdementen
Copy link
Contributor Author

yes indeed having a mandatory default may be a better idea. It is more the idea of having either a function defined on an interval only and outside not being defined (idea of default = Undefined). Typically if we would write

tr=TimeSeries(default=Undefined)
tr[2:5]=1.0

Then any evaluation outside [2:5[ would lead to an exception (tr[0], tr[10] but also tr[5]) or would be properly handled if with slides (tr[4:6] would return a new timeseries defined only on [4,6[).

If we just do

tr=TimeSeries(default=Undefined)
tr[2]=1.0

then the function would be defined on [2, inf[.

This impacts the way the default values are propagated (for example in the code https://github.com/stringertheory/traces/pull/134/files).
With a default value of None (not knowing if it was defined explicitly or to show nothing was given), the proper handling of the default value may be trickier to determine in these functions.

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

No branches or pull requests

2 participants