MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / rrulewrapper

Class rrulewrapper

lib/matplotlib/dates.py:943–1061  ·  view source on GitHub ↗

A simple wrapper around a `dateutil.rrule` allowing flexible date tick specifications.

Source from the content-addressed store, hash-verified

941
942
943class rrulewrapper:
944 """
945 A simple wrapper around a `dateutil.rrule` allowing flexible
946 date tick specifications.
947 """
948 def __init__(self, freq, tzinfo=None, **kwargs):
949 """
950 Parameters
951 ----------
952 freq : {YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY}
953 Tick frequency. These constants are defined in `dateutil.rrule`,
954 but they are accessible from `matplotlib.dates` as well.
955 tzinfo : `datetime.tzinfo`, optional
956 Time zone information. The default is None.
957 **kwargs
958 Additional keyword arguments are passed to the `dateutil.rrule`.
959 """
960 kwargs['freq'] = freq
961 self._base_tzinfo = tzinfo
962
963 self._update_rrule(**kwargs)
964
965 def set(self, **kwargs):
966 """Set parameters for an existing wrapper."""
967 self._construct.update(kwargs)
968
969 self._update_rrule(**self._construct)
970
971 def _update_rrule(self, **kwargs):
972 tzinfo = self._base_tzinfo
973
974 # rrule does not play nicely with timezones - especially pytz time
975 # zones, it's best to use naive zones and attach timezones once the
976 # datetimes are returned
977 if 'dtstart' in kwargs:
978 dtstart = kwargs['dtstart']
979 if dtstart.tzinfo is not None:
980 if tzinfo is None:
981 tzinfo = dtstart.tzinfo
982 else:
983 dtstart = dtstart.astimezone(tzinfo)
984
985 kwargs['dtstart'] = dtstart.replace(tzinfo=None)
986
987 if 'until' in kwargs:
988 until = kwargs['until']
989 if until.tzinfo is not None:
990 if tzinfo is not None:
991 until = until.astimezone(tzinfo)
992 else:
993 raise ValueError('until cannot be aware if dtstart '
994 'is naive and tzinfo is None')
995
996 kwargs['until'] = until.replace(tzinfo=None)
997
998 self._construct = kwargs.copy()
999 self._tzinfo = tzinfo
1000 self._rrule = rrule(**self._construct)

Callers 10

test_rrulewrapperFunction · 0.90
date_demo_rrule.pyFile · 0.90
get_locatorMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 1

test_rrulewrapperFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…