8000 Merge pull request #18957 from katleszek/doc-datetime · numpy/numpy@99b396b · GitHub
[go: up one dir, main page]

Skip to content

Commit 99b396b

Browse files
authored
Merge pull request #18957 from katleszek/doc-datetime
DOC: Improve datetime64 docs.
2 parents dfe38fd + 620ee78 commit 99b396b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

doc/source/reference/arrays.datetime.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ support datetime functionality. The data type is called "datetime64",
1313
so named because "datetime" is already taken by the datetime library
1414
included in Python.
1515

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

1917
Basic Datetimes
2018
===============
2119

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

3736
>>> np.datetime64('2005-02-25')
3837
numpy.datetime64('2005-02-25')
38+
39+
From an integer and a date unit, 1 year since the UNIX epoch:
40+
41+
>>> np.datetime64(1, 'Y')
42+
numpy.datetime64('1971')
3943

4044
Using months for the unit:
4145

numpy/core/_add_newdocs_scalars.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,15 @@ def add_newdoc_for_scalar_type(obj, fixed_aliases, doc):
218218

219219
add_newdoc_for_scalar_type('datetime64', [],
220220
"""
221-
A datetime stored as a 64-bit integer, counting from ``1970-01-01T00:00:00``.
221+
If created from a 64-bit integer, it represents an offset from
222+
``1970-01-01T00:00:00``.
223+
If created from string, the string can be in ISO 8601 date
224+
or datetime format.
222225
223226
>>> np.datetime64(10, 'Y')
224227
numpy.datetime64('1980')
228+
>>> np.datetime64('1980', 'Y')
229+
numpy.datetime64('1980')
225230
>>> np.datetime64(10, 'D')
226231
numpy.datetime64('1970-01-11')
227232

0 commit comments

Comments
 (0)
0