@@ -74,6 +74,8 @@ def _access_through_series(values, name):
74
74
if name == "season" :
75
75
months = values_as_series .dt .month .values
76
76
field_values = _season_from_months (months )
77
+ elif name == "total_seconds" :
78
+ field_values = values_as_series .dt .total_seconds ().values
77
79
elif name == "isocalendar" :
78
80
# special NaT-handling can be removed when
79
81
# https://github.com/pandas-dev/pandas/issues/54657 is resolved
@@ -574,6 +576,13 @@ class TimedeltaAccessor(TimeAccessor[T_DataArray]):
574
576
43200, 64800])
575
577
Coordinates:
576
578
* time (time) timedelta64[ns] 1 days 00:00:00 ... 5 days 18:00:00
579
+ >>> ts.dt.total_seconds()
580
+ <xarray.DataArray 'total_seconds' (time: 20)>
581
+ array([ 86400., 108000., 129600., 151200., 172800., 194400., 216000.,
582
+ 237600., 259200., 280800., 302400., 324000., 345600., 367200.,
583
+ 388800., 410400., 432000., 453600., 475200., 496800.])
584
+ Coordinates:
585
+ * time (time) timedelta64[ns] 1 days 00:00:00 ... 5 days 18:00:00
577
586
"""
578
587
579
588
@property
@@ -596,6 +605,11 @@ def nanoseconds(self) -> T_DataArray:
596
605
"""Number of nanoseconds (>= 0 and less than 1 microsecond) for each element"""
597
606
return self ._date_field ("nanoseconds" , np .int64 )
598
607
608
+ # Not defined as a property in order to match the Pandas API
609
+ def total_seconds (self ) -> T_DataArray :
610
+ """Total duration of each element expressed in seconds."""
611
+ return self ._date_field ("total_seconds" , np .float64 )
612
+
599
613
600
614
class CombinedDatetimelikeAccessor (
601
615
DatetimeAccessor [T_DataArray ], TimedeltaAccessor [T_DataArray ]
0 commit comments