Convert datetime objects to Matplotlib dates. Parameters ---------- d : `datetime.datetime` or `numpy.datetime64` or sequences of these Returns ------- float or sequence of floats Number of days (fraction part represents hours, minutes, seconds, ms) sin
(d)
| 391 | |
| 392 | |
| 393 | def date2num(d): |
| 394 | """ |
| 395 | Convert datetime objects to Matplotlib dates. |
| 396 | |
| 397 | Parameters |
| 398 | ---------- |
| 399 | d : `datetime.datetime` or `numpy.datetime64` or sequences of these |
| 400 | |
| 401 | Returns |
| 402 | ------- |
| 403 | float or sequence of floats |
| 404 | Number of days (fraction part represents hours, minutes, seconds, ms) |
| 405 | since 0001-01-01 00:00:00 UTC, plus one. |
| 406 | |
| 407 | Notes |
| 408 | ----- |
| 409 | The addition of one here is a historical artifact. Also, note that the |
| 410 | Gregorian calendar is assumed; this is not universal practice. |
| 411 | For details see the module docstring. |
| 412 | """ |
| 413 | if hasattr(d, "values"): |
| 414 | # this unpacks pandas series or dataframes... |
| 415 | d = d.values |
| 416 | if not np.iterable(d): |
| 417 | if (isinstance(d, np.datetime64) or (isinstance(d, np.ndarray) and |
| 418 | np.issubdtype(d.dtype, np.datetime64))): |
| 419 | return _dt64_to_ordinalf(d) |
| 420 | return _to_ordinalf(d) |
| 421 | |
| 422 | else: |
| 423 | d = np.asarray(d) |
| 424 | if np.issubdtype(d.dtype, np.datetime64): |
| 425 | return _dt64_to_ordinalf(d) |
| 426 | if not d.size: |
| 427 | return d |
| 428 | return _to_ordinalf_np_vectorized(d) |
| 429 | |
| 430 | |
| 431 | def julian2num(j): |
no test coverage detected