From daacc99a37f9021089cf04d5599ff79b30eac228 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 26 Aug 2017 17:35:10 +0100 Subject: [PATCH 1/3] Convert some dates.py docstrings to numpydoc --- lib/matplotlib/dates.py | 75 +++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 3dff61acfde8..2976c12e4c67 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -164,6 +164,7 @@ def tzname(self, dt): def dst(self, dt): return datetime.timedelta(0) + UTC = _UTC() @@ -327,8 +328,8 @@ def datestr2num(d, default=None): d : string or sequence of strings The dates to convert. - default : datetime instance - The default date to use when fields are missing in `d`. + default : datetime instance, optional + The default date to use when fields are missing in *d*. """ if isinstance(d, six.string_types): dt = dateutil.parser.parse(d, default=default) @@ -344,14 +345,23 @@ def datestr2num(d, default=None): def date2num(d): """ - *d* is either a :class:`datetime` instance or a sequence of datetimes. + Converts datetime objects to Matplotlib dates. + + Parameters + ---------- + d: :class:`datetime` or sequence of :class:`datetime` - Return value is a floating point number (or sequence of floats) - which gives the number of days (fraction part represents hours, - minutes, seconds) since 0001-01-01 00:00:00 UTC, *plus* *one*. - The addition of one here is a historical artifact. Also, note - that the Gregorian calendar is assumed; this is not universal - practice. For details, see the module docstring. + Returns + ------- + float or sequence of floats + Number of days (fraction part represents hours, minutes, seconds) + since 0001-01-01 00:00:00 UTC, plus one. + + Notes + ----- + The addition of one here is a historical artifact. Also, note that the + Gregorian calendar is assumed; this is not universal practice. + For details see the module docstring. """ if not cbook.iterable(d): return _to_ordinalf(d) @@ -365,6 +375,16 @@ def date2num(d): def julian2num(j): """ Convert a Julian date (or sequence) to a matplotlib date (or sequence). + + Parameters + ---------- + k: float or sequence of floats + Julian date(s) + + Returns + ------- + float or sequency of floats + Matplotlib date(s) """ if cbook.iterable(j): j = np.asarray(j) @@ -373,7 +393,17 @@ def julian2num(j): def num2julian(n): """ - Convert a matplotlib date (or sequence) to a Julian date (or sequence). + Convert a Matplotlib date (or sequence) to a Julian date (or sequence). + + Parameters + ---------- + n: float or sequence of floats + Matplotlib date(s) + + Returns + ------- + float or sequency of floats + Julian date(s) """ if cbook.iterable(n): n = np.asarray(n) @@ -382,18 +412,27 @@ def num2julian(n): def num2date(x, tz=None): """ - *x* is a float value which gives the number of days - (fraction part represents hours, minutes, seconds) since - 0001-01-01 00:00:00 UTC *plus* *one*. - The addition of one here is a historical artifact. Also, note - that the Gregorian calendar is assumed; this is not universal - practice. For details, see the module docstring. + Parameters + ---------- + x: float + Number of days (fraction part represents hours, minutes, seconds) + since 0001-01-01 00:00:00 UTC, plus one. + tz: string, optional + Timezone of *x* (defaults to rcparams TZ value). - Return value is a :class:`datetime` instance in timezone *tz* (default to - rcparams TZ value). + Returns + ------- + :class:`datetime` or sequence of :class:`datetime` + Dates are returned in timezone *tz* If *x* is a sequence, a sequence of :class:`datetime` objects will be returned. + + Notes + ----- + The addition of one here is a historical artifact. Also, note that the + Gregorian calendar is assumed; this is not universal practice. + For details, see the module docstring. """ if tz is None: tz = _get_rc_timezone() From c7203644e6e29db4f609235b36a8836e07529580 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 26 Aug 2017 17:57:57 +0100 Subject: [PATCH 2/3] Add spaces after parameter names --- lib/matplotlib/dates.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 2976c12e4c67..bfff576be0e5 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -178,6 +178,7 @@ def _get_rc_timezone(): import pytz return pytz.timezone(s) + """ Time-related constants. """ @@ -349,7 +350,7 @@ def date2num(d): Parameters ---------- - d: :class:`datetime` or sequence of :class:`datetime` + d : :class:`datetime` or sequence of :class:`datetime` Returns ------- @@ -378,7 +379,7 @@ def julian2num(j): Parameters ---------- - k: float or sequence of floats + k : float or sequence of floats Julian date(s) Returns @@ -397,7 +398,7 @@ def num2julian(n): Parameters ---------- - n: float or sequence of floats + n : float or sequence of floats Matplotlib date(s) Returns @@ -414,10 +415,10 @@ def num2date(x, tz=None): """ Parameters ---------- - x: float + x : float or sequence of floats Number of days (fraction part represents hours, minutes, seconds) since 0001-01-01 00:00:00 UTC, plus one. - tz: string, optional + tz : string, optional Timezone of *x* (defaults to rcparams TZ value). Returns From d9965e366468503f9360e4eecfb5d07c05e80e65 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 27 Aug 2017 12:56:04 +0100 Subject: [PATCH 3/3] Fix sequence spelling --- lib/matplotlib/dates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index bfff576be0e5..6ab361714ec1 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -384,7 +384,7 @@ def julian2num(j): Returns ------- - float or sequency of floats + float or sequence of floats Matplotlib date(s) """ if cbook.iterable(j): @@ -403,7 +403,7 @@ def num2julian(n): Returns ------- - float or sequency of floats + float or sequence of floats Julian date(s) """ if cbook.iterable(n):