8000 DOC: Improve datetime64 docs. by katleszek · Pull Request #18957 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: Improve datetime64 docs. #18957

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 10 commits into from
May 11, 2021
16 changes: 10 additions & 6 deletions doc/source/reference/arrays.datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ support datetime functionality. The data type is called "datetime64",
so named because "datetime" is already taken by the datetime library
included in Python.

.. note:: The datetime API is *experimental* in 1.7.0, and may undergo changes
in future versions of NumPy.

Basic Datetimes
===============

The most basic way to create datetimes is from strings in
ISO 8601 date or datetime format. The unit for internal storage
is automatically selected from the form of the string, and can
be either a :ref:`date unit <arrays.dtypes.dateunits>` or a
The most basic way to create datetimes is from strings in ISO 8601 date
or datetime format. It is also possible to create datetimes from an integer by
offset relative to the Unix epoch (00:00:00 UTC on 1 January 1970).
The unit for internal storage is automatically selected from the
form of the string, and can be either a :ref:`date unit <arrays.dtypes.dateunits>` or a
:ref:`time unit <arrays.dtypes.timeunits>`. The date units are years ('Y'),
months ('M'), weeks ('W'), and days ('D'), while the time units are
hours ('h'), minutes ('m'), seconds ('s'), milliseconds ('ms'), and
Expand All @@ -36,6 +35,11 @@ letters, for a "Not A Time" value.

>>> np.datetime64('2005-02-25')
numpy.datetime64('2005-02-25')

From an integer and a date unit, 1 year since the UNIX epoch:

>>> np.datetime64(1, 'Y')
numpy.datetime64('1971')

Using months for the unit:

Expand Down
7 changes: 6 additions & 1 deletion numpy/core/_add_newdocs_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,15 @@ def add_newdoc_for_scalar_type(obj, fixed_aliases, doc):

add_newdoc_for_scalar_type('datetime64', [],
"""
A datetime stored as a 64-bit integer, counting from ``1970-01-01T00:00:00``.
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't it make sense to keep this description too? This change seems to remove information about datetime64 and add information about datetime64.__new__. Ideally we'd have both!

Copy link
Member

Choose a reason for hiding this comment

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

Sure.

If created from a 64-bit integer, it represents an offset from
``1970-01-01T00:00:00``.
If created from string, the string must be in ISO 8601 date
or datetime format.

>>> np.datetime64(10, 'Y')
numpy.datetime64('1980')
>>> np.datetime64('1980', 'Y')
numpy.datetime64('1980')
>>> np.datetime64(10, 'D')
numpy.datetime64('1970-01-11')

Expand Down
0