@@ -2429,9 +2429,11 @@ def _is_monotonic(
2429
2429
block , last_notna_id = self .apply_unary_op (column_ids [0 ], ops .notnull_op )
2430
2430
for column_id in column_ids [1 :]:
2431
2431
block , notna_id = block .apply_unary_op (column_id , ops .notnull_op )
2432
+ old_last_notna_id = last_notna_id
2432
2433
block , last_notna_id = block .apply_binary_op (
2433
- last_notna_id , notna_id , ops .and_op
2434
+ old_last_notna_id , notna_id , ops .and_op
2434
2435
)
2436
+ block .drop_columns ([notna_id , old_last_notna_id ])
2435
2437
2436
2438
# loop over all columns to check monotonicity
2437
2439
last_result_id = None
@@ -2443,21 +2445,27 @@ def _is_monotonic(
2443
2445
column_id , lag_result_id , ops .gt_op if increasing else ops .lt_op
2444
2446
)
2445
2447
block , equal_id = block .apply_binary_op (column_id , lag_result_id , ops .eq_op )
2448
+ block = block .drop_columns ([lag_result_id ])
2446
2449
if last_result_id is None :
2447
2450
block , last_result_id = block .apply_binary_op (
2448
2451
equal_id , strict_monotonic_id , ops .or_op
2449
2452
)
2450
- continue
2451
- block , equal_monotonic_id = block .apply_binary_op (
2452
- equal_id , last_result_id , ops .and_op
2453
- )
2454
- block , last_result_id = block .apply_binary_op (
2455
- equal_monotonic_id , strict_monotonic_id , ops .or_op
2456
- )
2453
+ block = block .drop_columns ([equal_id , strict_monotonic_id ])
2454
+ else :
2455
+ block , equal_monotonic_id = block .apply_binary_op (
2456
+ equal_id , last_result_id , ops .and_op
2457
+ )
2458
+ block = block .drop_columns ([equal_id , last_result_id ])
2459
+ block , last_result_id = block .apply_binary_op (
2460
+ equal_monotonic_id , strict_monotonic_id , ops .or_op
2461
+ )
2462
+ block = block .drop_columns ([equal_monotonic_id , strict_monotonic_id ])
2457
2463
2458
2464
block , monotonic_result_id = block .apply_binary_op (
2459
2465
last_result_id , last_notna_id , ops .and_op # type: ignore
2460
2466
)
2467
+ if last_result_id is not None :
2468
+ block = block .drop_columns ([last_result_id , last_notna_id ])
2461
2469
result = block .get_stat (monotonic_result_id , agg_ops .all_op )
2462
2470
self ._stats_cache [column_name ].update ({op_name : result })
2463
2471
return result
0 commit comments