Skip to content

Add rrulewrapper to docs #23048

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

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/dates_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
.. automodule:: matplotlib.dates
:members:
:undoc-members:
:exclude-members: rrule
:show-inheritance:
20 changes: 16 additions & 4 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@

* `YearLocator`: Locate years that are multiples of base.

* `RRuleLocator`: Locate using a ``matplotlib.dates.rrulewrapper``.
``rrulewrapper`` is a simple wrapper around dateutil_'s `dateutil.rrule`
* `RRuleLocator`: Locate using a `rrulewrapper`.
`rrulewrapper` is a simple wrapper around dateutil_'s `dateutil.rrule`
which allow almost arbitrary date tick specifications.
See :doc:`rrule example </gallery/ticks/date_demo_rrule>`.

Expand Down Expand Up @@ -195,7 +195,7 @@
'rrule', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU',
'YEARLY', 'MONTHLY', 'WEEKLY', 'DAILY',
'HOURLY', 'MINUTELY', 'SECONDLY', 'MICROSECONDLY', 'relativedelta',
'DateConverter', 'ConciseDateConverter')
'DateConverter', 'ConciseDateConverter', 'rrulewrapper')


_log = logging.getLogger(__name__)
Expand Down Expand Up @@ -981,16 +981,28 @@ def __call__(self, x, pos=None):

class rrulewrapper:
"""
A simple wrapper around a ``dateutil.rrule`` allowing flexible
A simple wrapper around a `dateutil.rrule` allowing flexible
date tick specifications.
Copy link
Member

Choose a reason for hiding this comment

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

Can we add some clue here as to how this is supposed to be used? There are no documented methods on the class, which is probably fine, but as it stands this is kind of mysterious. Maybe:

Suggested change
date tick specifications.
date tick specifications. Usually passed upon init to a subclass of `RRuleLocator`.

I will say that adding this wrapper seems a bit cumbersome versus just passing freq, tzinfo etc to the RRuleLocator directly. If it were up to me, I'd deprecate rrulewrapper as public and get rid of it all together.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK! I do not have any strong opinions on it. Clearly people have managed without it being documented for quite some time now.

Copy link
Member

Choose a reason for hiding this comment

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

Well I doubt we will deprecate it now - lets improve the docs even if it doesn't stick around.

"""
def __init__(self, freq, tzinfo=None, **kwargs):
"""
Parameters
----------
freq : {YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY}
Tick frequency. These constants are defined in `dateutil.rrule`,
but they are accessible from `matplotlib.dates` as well.
tzinfo : `datetime.tzinfo`, optional
Time zone information. The default is None.
**kwargs
Additional keyword arguments are passed to the `dateutil.rrule`.
"""
kwargs['freq'] = freq
self._base_tzinfo = tzinfo

self._update_rrule(**kwargs)

def set(self, **kwargs):
"""Set parameters for an existing wrapper."""
self._construct.update(kwargs)

self._update_rrule(**self._construct)
Expand Down