@@ -480,21 +480,19 @@ def _is_monotonic(self, order):
480480 return self ._is_monotonic_decreasing ().all ()
481481
482482 def _is_monotonic_increasing (self ):
483- scol = self .spark .column
484483 window = Window .orderBy (NATURAL_ORDER_COLUMN_NAME ).rowsBetween (- 1 , - 1 )
485- prev = F .lag (scol , 1 ).over (window )
486484
487485 cond = F .lit (True )
488486 has_not_null = F .lit (True )
489- for field in self .spark . data_type [::- 1 ]:
490- left = scol . getField ( field . name )
491- right = prev . getField ( field . name )
492- compare = MultiIndex ._comparator_for_monotonic_increasing (field . dataType )
487+ for scol in self ._internal . index_spark_columns [::- 1 ]:
488+ data_type = self . _internal . spark_type_for ( scol )
489+ prev = F . lag ( scol , 1 ). over ( window )
490+ compare = MultiIndex ._comparator_for_monotonic_increasing (data_type )
493491 # Since pandas 1.1.4, null value is not allowed at any levels of MultiIndex.
494492 # Therefore, we should check `has_not_null` over the all levels.
495- has_not_null = has_not_null & left .isNotNull ()
496- cond = F .when (left .eqNullSafe (right ), cond ).otherwise (
497- compare (left , right , spark .Column .__gt__ )
493+ has_not_null = has_not_null & scol .isNotNull ()
494+ cond = F .when (scol .eqNullSafe (prev ), cond ).otherwise (
495+ compare (scol , prev , spark .Column .__gt__ )
498496 )
499497
500498 cond = has_not_null & (prev .isNull () | cond )
@@ -524,21 +522,19 @@ def _comparator_for_monotonic_decreasing(data_type):
524522 return compare_disallow_null
525523
526524 def _is_monotonic_decreasing (self ):
527- scol = self .spark .column
528525 window = Window .orderBy (NATURAL_ORDER_COLUMN_NAME ).rowsBetween (- 1 , - 1 )
529- prev = F .lag (scol , 1 ).over (window )
530526
531527 cond = F .lit (True )
532528 has_not_null = F .lit (True )
533- for field in self .spark . data_type [::- 1 ]:
534- left = scol . getField ( field . name )
535- right = prev . getField ( field . name )
536- compare = MultiIndex ._comparator_for_monotonic_decreasing ( field . dataType )
529+ for scol in self ._internal . index_spark_columns [::- 1 ]:
530+ data_type = self . _internal . spark_type_for ( scol )
531+ prev = F . lag ( scol , 1 ). over ( window )
532+ compare = MultiIndex ._comparator_for_monotonic_increasing ( data_type )
537533 # Since pandas 1.1.4, null value is not allowed at any levels of MultiIndex.
538534 # Therefore, we should check `has_not_null` over the all levels.
539- has_not_null = has_not_null & left .isNotNull ()
540- cond = F .when (left .eqNullSafe (right ), cond ).otherwise (
541- compare (left , right , spark .Column .__lt__ )
535+ has_not_null = has_not_null & scol .isNotNull ()
536+ cond = F .when (scol .eqNullSafe (prev ), cond ).otherwise (
537+ compare (scol , prev , spark .Column .__lt__ )
542538 )
543539
544540 cond = has_not_null & (prev .isNull () | cond )
0 commit comments