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

rename factory methods #60

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

Conversation

carlculator
Copy link
Owner

deprecate TimestampSeries.create_null_timeseries and TimestampSeries.create_constant_timeseries, rename to
TimestampSeries.create_null_series and TimestampSeries.create_constant_series.

motivation:
the created series is a Timestamp-Series, a Time-Series and a Series. The most explicit name would be create_constant_timestampseries. Since this is already provided by the namespace of the class, I'd go for the most generic version, which is Series.

Signed-off-by: carlculator <info@alexander-schulz.eu>
@carlculator carlculator self-assigned this Jul 19, 2022
timeseriesx/base/timestamp_series.py Outdated Show resolved Hide resolved
return TimestampSeries.create_null_series(start, end, freq, unit=unit,
time_zone=time_zone)

@staticmethod
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using classmethod instead of staticmethod allows avoiding hardcoding the class name for inheritance.

Copy link
Owner Author

Choose a reason for hiding this comment

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

good point. changed this

Copy link
Collaborator

Choose a reason for hiding this comment

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

For backward compatibility, the old (now deprecated) methods must remain decorated with staticmethod.

unit=unit, time_zone=time_zone)

@staticmethod
def create_constant_series(start, end, value, freq, unit=None, time_zone='infer'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

start, end and perhaps value are readable enough when positional, but freq and especially unit and time_zone are better given as keywords only. This is also how the mixins require it. As such, I would change the definition to:

def create_constant_series(start, end, value, *, freq, unit=None, time_zone="infer"): ...

Copy link
Owner Author

Choose a reason for hiding this comment

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

I like this idea of keywords only. I did not apply it elsewhere in the code, so maybe it would be better to overhaul this globally in one go? What do you think? I don't understand how the mixins affect this factory method?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree keywords only and positional only arguments make for cleaner interfaces, but introducing them after the fact comes with a lot of backward incompatibility. Perhaps a good issue to tackle before a major release.

The mixins are already implicitly keyword only because they only work when the arguments like freq are given as keywords. This is because they get their data only from **kwargs and never from *args (which would be tricky). Try running the tests after changing the keyword arguments of the super constructor call in TimestampSeries.__init__ to positional arguments to see that it does not work. That is not strictly related to this factory method, but they both create instances from very similar arguments, hence the comparison.

Comment on lines 106 to 110
warnings.warn("this method was renamed, and will be deprecated in a future "
"version, please use `create_constant_series` instead",
category=DeprecationWarning)
return TimestampSeries.create_constant_series(start, end, value, freq,
unit=unit, time_zone=time_zone)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if #53 is not yet merged, you can already start using Black (which would be easier if it were merged).

Signed-off-by: carlculator <info@alexander-schulz.eu>
Signed-off-by: carlculator <info@alexander-schulz.eu>
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.

None yet

2 participants