Skip to content

Commit 2270786

Browse files
authored
Merge pull request numpy#26322 from ajayjanapareddi/main
DOC: Documentation and examples for conversion of np.timedelta64 units
2 parents 0310e17 + dcd896f commit 2270786

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

doc/source/reference/arrays.datetime.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,12 @@ simple datetime calculations.
205205
There are two Timedelta units ('Y', years and 'M', months) which are treated
206206
specially, because how much time they represent changes depending
207207
on when they are used. While a timedelta day unit is equivalent to
208-
24 hours, there is no way to convert a month unit into days, because
209-
different months have different numbers of days.
208+
24 hours, month and year units cannot be converted directly into days
209+
without using 'unsafe' casting.
210+
211+
The `numpy.ndarray.astype` method can be used for unsafe
212+
conversion of months/years to days. The conversion follows
213+
calculating the averaged values from the 400 year leap-year cycle.
210214

211215
.. admonition:: Example
212216

@@ -220,6 +224,7 @@ different months have different numbers of days.
220224
File "<stdin>", line 1, in <module>
221225
TypeError: Cannot cast NumPy timedelta64 scalar from metadata [Y] to [D] according to the rule 'same_kind'
222226

227+
223228
Datetime units
224229
==============
225230

0 commit comments

Comments
 (0)