@@ -111,7 +111,7 @@ def _rewrite_expressions(expr: ex.Expression, schema: schema.ArraySchema) -> _Ty
111111
112112
113113def _rewrite_scalar_constant_expr (expr : ex .ScalarConstantExpression ) -> _TypedExpr :
114- if expr .dtype is dtypes .TIMEDELTA_DTYPE :
114+ if expr .dtype == dtypes .TIMEDELTA_DTYPE :
115115 int_repr = utils .timedelta_to_micros (expr .value ) # type: ignore
116116 return _TypedExpr (ex .const (int_repr , expr .dtype ), expr .dtype )
117117
@@ -148,31 +148,31 @@ def _rewrite_sub_op(left: _TypedExpr, right: _TypedExpr) -> _TypedExpr:
148148 if dtypes .is_datetime_like (left .dtype ) and dtypes .is_datetime_like (right .dtype ):
149149 return _TypedExpr .create_op_expr (ops .timestamp_diff_op , left , right )
150150
151- if dtypes .is_datetime_like (left .dtype ) and right .dtype is dtypes .TIMEDELTA_DTYPE :
151+ if dtypes .is_datetime_like (left .dtype ) and right .dtype == dtypes .TIMEDELTA_DTYPE :
152152 return _TypedExpr .create_op_expr (ops .timestamp_sub_op , left , right )
153153
154154 if left .dtype == dtypes .DATE_DTYPE and right .dtype == dtypes .DATE_DTYPE :
155155 return _TypedExpr .create_op_expr (ops .date_diff_op , left , right )
156156
157- if left .dtype == dtypes .DATE_DTYPE and right .dtype is dtypes .TIMEDELTA_DTYPE :
157+ if left .dtype == dtypes .DATE_DTYPE and right .dtype == dtypes .TIMEDELTA_DTYPE :
158158 return _TypedExpr .create_op_expr (ops .date_sub_op , left , right )
159159
160160 return _TypedExpr .create_op_expr (ops .sub_op , left , right )
161161
162162
163163def _rewrite_add_op (left : _TypedExpr , right : _TypedExpr ) -> _TypedExpr :
164- if dtypes .is_datetime_like (left .dtype ) and right .dtype is dtypes .TIMEDELTA_DTYPE :
164+ if dtypes .is_datetime_like (left .dtype ) and right .dtype == dtypes .TIMEDELTA_DTYPE :
165165 return _TypedExpr .create_op_expr (ops .timestamp_add_op , left , right )
166166
167- if left .dtype is dtypes .TIMEDELTA_DTYPE and dtypes .is_datetime_like (right .dtype ):
167+ if left .dtype == dtypes .TIMEDELTA_DTYPE and dtypes .is_datetime_like (right .dtype ):
168168 # Re-arrange operands such that timestamp is always on the left and timedelta is
169169 # always on the right.
170170 return _TypedExpr .create_op_expr (ops .timestamp_add_op , right , left )
171171
172- if left .dtype == dtypes .DATE_DTYPE and right .dtype is dtypes .TIMEDELTA_DTYPE :
172+ if left .dtype == dtypes .DATE_DTYPE and right .dtype == dtypes .TIMEDELTA_DTYPE :
173173 return _TypedExpr .create_op_expr (ops .date_add_op , left , right )
174174
175- if left .dtype is dtypes .TIMEDELTA_DTYPE and right .dtype == dtypes .DATE_DTYPE :
175+ if left .dtype == dtypes .TIMEDELTA_DTYPE and right .dtype == dtypes .DATE_DTYPE :
176176 # Re-arrange operands such that date is always on the left and timedelta is
177177 # always on the right.
178178 return _TypedExpr .create_op_expr (ops .date_add_op , right , left )
@@ -183,9 +183,9 @@ def _rewrite_add_op(left: _TypedExpr, right: _TypedExpr) -> _TypedExpr:
183183def _rewrite_mul_op (left : _TypedExpr , right : _TypedExpr ) -> _TypedExpr :
184184 result = _TypedExpr .create_op_expr (ops .mul_op , left , right )
185185
186- if left .dtype is dtypes .TIMEDELTA_DTYPE and dtypes .is_numeric (right .dtype ):
186+ if left .dtype == dtypes .TIMEDELTA_DTYPE and dtypes .is_numeric (right .dtype ):
187187 return _TypedExpr .create_op_expr (ops .timedelta_floor_op , result )
188- if dtypes .is_numeric (left .dtype ) and right .dtype is dtypes .TIMEDELTA_DTYPE :
188+ if dtypes .is_numeric (left .dtype ) and right .dtype == dtypes .TIMEDELTA_DTYPE :
189189 return _TypedExpr .create_op_expr (ops .timedelta_floor_op , result )
190190
191191 return result
@@ -194,7 +194,7 @@ def _rewrite_mul_op(left: _TypedExpr, right: _TypedExpr) -> _TypedExpr:
194194def _rewrite_div_op (left : _TypedExpr , right : _TypedExpr ) -> _TypedExpr :
195195 result = _TypedExpr .create_op_expr (ops .div_op , left , right )
196196
197- if left .dtype is dtypes .TIMEDELTA_DTYPE and dtypes .is_numeric (right .dtype ):
197+ if left .dtype == dtypes .TIMEDELTA_DTYPE and dtypes .is_numeric (right .dtype ):
198198 return _TypedExpr .create_op_expr (ops .timedelta_floor_op , result )
199199
200200 return result
@@ -203,14 +203,14 @@ def _rewrite_div_op(left: _TypedExpr, right: _TypedExpr) -> _TypedExpr:
203203def _rewrite_floordiv_op (left : _TypedExpr , right : _TypedExpr ) -> _TypedExpr :
204204 result = _TypedExpr .create_op_expr (ops .floordiv_op , left , right )
205205
206- if left .dtype is dtypes .TIMEDELTA_DTYPE and dtypes .is_numeric (right .dtype ):
206+ if left .dtype == dtypes .TIMEDELTA_DTYPE and dtypes .is_numeric (right .dtype ):
207207 return _TypedExpr .create_op_expr (ops .timedelta_floor_op , result )
208208
209209 return result
210210
211211
212212def _rewrite_to_timedelta_op (op : ops .ToTimedeltaOp , arg : _TypedExpr ):
213- if arg .dtype is dtypes .TIMEDELTA_DTYPE :
213+ if arg .dtype == dtypes .TIMEDELTA_DTYPE :
214214 # Do nothing for values that are already timedeltas
215215 return arg
216216
@@ -239,19 +239,19 @@ def _rewrite_aggregation(
239239 aggs .DateSeriesDiffOp (aggregation .op .periods ), aggregation .arg
240240 )
241241
242- if isinstance (aggregation .op , aggs .StdOp ) and input_type is dtypes .TIMEDELTA_DTYPE :
242+ if isinstance (aggregation .op , aggs .StdOp ) and input_type == dtypes .TIMEDELTA_DTYPE :
243243 return ex .UnaryAggregation (
244244 aggs .StdOp (should_floor_result = True ), aggregation .arg
245245 )
246246
247- if isinstance (aggregation .op , aggs .MeanOp ) and input_type is dtypes .TIMEDELTA_DTYPE :
247+ if isinstance (aggregation .op , aggs .MeanOp ) and input_type == dtypes .TIMEDELTA_DTYPE :
248248 return ex .UnaryAggregation (
249249 aggs .MeanOp (should_floor_result = True ), aggregation .arg
250250 )
251251
252252 if (
253253 isinstance (aggregation .op , aggs .QuantileOp )
254- and input_type is dtypes .TIMEDELTA_DTYPE
254+ and input_type == dtypes .TIMEDELTA_DTYPE
255255 ):
256256 return ex .UnaryAggregation (
257257 aggs .QuantileOp (q = aggregation .op .q , should_floor_result = True ),
0 commit comments