Skip to content

Commit 619485d

Browse files
committed
Use a timedelta64 object in get_track_duration to safely determine the time units
1 parent 8bfc32f commit 619485d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

huracanpy/calc/_track_stats.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ def get_track_duration(time, track_ids):
1212
1313
Parameters
1414
----------
15-
time
16-
track_ids
15+
time : xarray.DataArray
16+
track_ids : array_like
1717
1818
Returns
1919
-------
2020
xarray.DataArray
21-
Duration of each track
21+
Duration of each track (in hours)
2222
2323
"""
2424
duration = (
2525
time.groupby(track_ids).map(lambda x: x.max() - x.min()).rename("duration")
2626
)
27-
duration = (duration * 1e-9 / 3600).astype(float)
28-
duration.attrs["units"] = "h"
27+
duration = duration / np.timedelta64(1, "h")
28+
duration.attrs["units"] = "hours"
2929
return duration
3030

3131

0 commit comments

Comments
 (0)