Skip to content

Commit e7da181

Browse files
authored
Merge pull request #9102 from dstansby/dates-docstrings
DOC: Convert some dates.py docstrings to numpydoc
2 parents 24de043 + d9965e3 commit e7da181

File tree

1 file changed

+58
-18
lines changed

1 file changed

+58
-18
lines changed

lib/matplotlib/dates.py

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def tzname(self, dt):
164164
def dst(self, dt):
165165
return datetime.timedelta(0)
166166

167+
167168
UTC = _UTC()
168169

169170

@@ -177,6 +178,7 @@ def _get_rc_timezone():
177178
import pytz
178179
return pytz.timezone(s)
179180

181+
180182
"""
181183
Time-related constants.
182184
"""
@@ -327,8 +329,8 @@ def datestr2num(d, default=None):
327329
d : string or sequence of strings
328330
The dates to convert.
329331
330-
default : datetime instance
331-
The default date to use when fields are missing in `d`.
332+
default : datetime instance, optional
333+
The default date to use when fields are missing in *d*.
332334
"""
333335
if isinstance(d, six.string_types):
334336
dt = dateutil.parser.parse(d, default=default)
@@ -344,14 +346,23 @@ def datestr2num(d, default=None):
344346

345347
def date2num(d):
346348
"""
347-
*d* is either a :class:`datetime` instance or a sequence of datetimes.
349+
Converts datetime objects to Matplotlib dates.
350+
351+
Parameters
352+
----------
353+
d : :class:`datetime` or sequence of :class:`datetime`
354+
355+
Returns
356+
-------
357+
float or sequence of floats
358+
Number of days (fraction part represents hours, minutes, seconds)
359+
since 0001-01-01 00:00:00 UTC, plus one.
348360
349-
Return value is a floating point number (or sequence of floats)
350-
which gives the number of days (fraction part represents hours,
351-
minutes, seconds) since 0001-01-01 00:00:00 UTC, *plus* *one*.
352-
The addition of one here is a historical artifact. Also, note
353-
that the Gregorian calendar is assumed; this is not universal
354-
practice. For details, see the module docstring.
361+
Notes
362+
-----
363+
The addition of one here is a historical artifact. Also, note that the
364+
Gregorian calendar is assumed; this is not universal practice.
365+
For details see the module docstring.
355366
"""
356367
if not cbook.iterable(d):
357368
return _to_ordinalf(d)
@@ -365,6 +376,16 @@ def date2num(d):
365376
def julian2num(j):
366377
"""
367378
Convert a Julian date (or sequence) to a matplotlib date (or sequence).
379+
380+
Parameters
381+
----------
382+
k : float or sequence of floats
383+
Julian date(s)
384+
385+
Returns
386+
-------
387+
float or sequence of floats
388+
Matplotlib date(s)
368389
"""
369390
if cbook.iterable(j):
370391
j = np.asarray(j)
@@ -373,7 +394,17 @@ def julian2num(j):
373394

374395
def num2julian(n):
375396
"""
376-
Convert a matplotlib date (or sequence) to a Julian date (or sequence).
397+
Convert a Matplotlib date (or sequence) to a Julian date (or sequence).
398+
399+
Parameters
400+
----------
401+
n : float or sequence of floats
402+
Matplotlib date(s)
403+
404+
Returns
405+
-------
406+
float or sequence of floats
407+
Julian date(s)
377408
"""
378409
if cbook.iterable(n):
379410
n = np.asarray(n)
@@ -382,18 +413,27 @@ def num2julian(n):
382413

383414
def num2date(x, tz=None):
384415
"""
385-
*x* is a float value which gives the number of days
386-
(fraction part represents hours, minutes, seconds) since
387-
0001-01-01 00:00:00 UTC *plus* *one*.
388-
The addition of one here is a historical artifact. Also, note
389-
that the Gregorian calendar is assumed; this is not universal
390-
practice. For details, see the module docstring.
416+
Parameters
417+
----------
418+
x : float or sequence of floats
419+
Number of days (fraction part represents hours, minutes, seconds)
420+
since 0001-01-01 00:00:00 UTC, plus one.
421+
tz : string, optional
422+
Timezone of *x* (defaults to rcparams TZ value).
391423
392-
Return value is a :class:`datetime` instance in timezone *tz* (default to
393-
rcparams TZ value).
424+
Returns
425+
-------
426+
:class:`datetime` or sequence of :class:`datetime`
427+
Dates are returned in timezone *tz*
394428
395429
If *x* is a sequence, a sequence of :class:`datetime` objects will
396430
be returned.
431+
432+
Notes
433+
-----
434+
The addition of one here is a historical artifact. Also, note that the
435+
Gregorian calendar is assumed; this is not universal practice.
436+
For details, see the module docstring.
397437
"""
398438
if tz is None:
399439
tz = _get_rc_timezone()

0 commit comments

Comments
 (0)