@@ -109,7 +109,8 @@ serialization_mode! {
109
109
}
110
110
111
111
impl TimedeltaMode {
112
- fn total_seconds < ' py > ( py_timedelta : & Bound < ' py , PyDelta > ) -> PyResult < Bound < ' py , PyAny > > {
112
+ fn total_seconds < ' py > ( py : Python , either_delta : & EitherTimedelta ) -> PyResult < Bound < ' py , PyAny > > {
113
+ let py_timedelta = either_delta. try_into_py ( py) ?;
113
114
py_timedelta. call_method0 ( intern ! ( py_timedelta. py( ) , "total_seconds" ) )
114
115
}
115
116
@@ -122,15 +123,13 @@ impl TimedeltaMode {
122
123
Self :: Float => {
123
124
// convert to int via a py timedelta not duration since we know this this case the input would have
124
125
// been a py timedelta
125
- let py_timedelta = either_delta. try_into_py ( py) ?;
126
- let seconds = Self :: total_seconds ( & py_timedelta) ?;
126
+ let seconds = Self :: total_seconds ( py, either_delta) ?;
127
127
Ok ( seconds. into_py ( py) )
128
128
}
129
129
Self :: Millisecond => {
130
130
// convert to int via a py timedelta not duration since we know this this case the input would have
131
131
// been a py timedelta
132
- let py_timedelta = either_delta. try_into_py ( py) ?;
133
- let seconds: f64 = Self :: total_seconds ( & py_timedelta) ?. extract ( ) ?;
132
+ let seconds = Self :: total_seconds ( py, either_delta) ?;
134
133
let object: Bound < PyFloat > = PyFloat :: new_bound ( py, seconds * 1000.0 ) ;
135
134
Ok ( object. into_py ( py) )
136
135
}
@@ -144,13 +143,11 @@ impl TimedeltaMode {
144
143
Ok ( d. to_string ( ) . into ( ) )
145
144
}
146
145
Self :: Float => {
147
- let py_timedelta = either_delta. try_into_py ( py) ?;
148
- let seconds: f64 = Self :: total_seconds ( & py_timedelta) ?. extract ( ) ?;
146
+ let seconds = Self :: total_seconds ( py, either_delta) ?. extract ( ) ?;
149
147
Ok ( seconds. to_string ( ) . into ( ) )
150
148
}
151
149
Self :: Millisecond => {
152
- let py_timedelta = either_delta. try_into_py ( py) ?;
153
- let seconds: f64 = Self :: total_seconds ( & py_timedelta) ?. extract ( ) ?;
150
+ let seconds = Self :: total_seconds ( py, either_delta) ?. extract ( ) ?;
154
151
let milliseconds: f64 = seconds * 1000.0 ;
155
152
Ok ( milliseconds. to_string ( ) . into ( ) )
156
153
}
@@ -169,15 +166,15 @@ impl TimedeltaMode {
169
166
serializer. serialize_str ( & d. to_string ( ) )
170
167
}
171
168
Self :: Float => {
172
- let py_timedelta = either_delta . try_into_py ( py) . map_err ( py_err_se_err ) ? ;
173
- let seconds = Self :: total_seconds ( & py_timedelta ) . map_err ( py_err_se_err ) ? ;
174
- let seconds : f64 = seconds . extract ( ) . map_err ( py_err_se_err) ?;
169
+ let seconds = Self :: total_seconds ( py, either_delta ) ?
170
+ . extract ( ) ?
171
+ . map_err ( py_err_se_err) ?;
175
172
serializer. serialize_f64 ( seconds)
176
173
}
177
174
Self :: Millisecond => {
178
- let py_timedelta = either_delta . try_into_py ( py) . map_err ( py_err_se_err ) ? ;
179
- let seconds = Self :: total_seconds ( & py_timedelta ) . map_err ( py_err_se_err ) ? ;
180
- let seconds : f64 = seconds . extract ( ) . map_err ( py_err_se_err) ?;
175
+ let seconds = Self :: total_seconds ( py, either_delta ) ?
176
+ . extract ( ) ?
177
+ . map_err ( py_err_se_err) ?;
181
178
let milliseconds: f64 = seconds * 1000.0 ;
182
179
serializer. serialize_f64 ( milliseconds)
183
180
}
0 commit comments