@@ -371,3 +371,139 @@ end
371371 @test sort (ds, :) == sort (ds[! , 1 : 2 ], :)
372372 end
373373end
374+
375+ @testset " issorted/issorted!" begin
376+ dv1 = [9 , 1 , 8 , missing , 3 , 3 , 7 , missing ]
377+ dv2 = [9 , 1 , 8 , missing , 3 , 3 , 7 , missing ]
378+ dv3 = Vector {Union{Int, Missing}} (1 : 8 )
379+ cv1 = CategoricalArray (dv1, ordered= true )
380+
381+ d = Dataset (dv1= dv1, dv2= dv2, dv3= dv3, cv1= cv1)
382+
383+ @test ! issorted (d, :cv1 )
384+ @test issorted (d, :dv3 )
385+ @test ! issorted (d, :dv1 )
386+
387+ dv1 = [1 ,3 ,3 ,7 ,8 ,9 , missing , missing ]
388+ dv2 = [9 , 1 , 8 , missing , 3 , 3 , 7 , missing ]
389+ dv3 = Vector {Union{Int, Missing}} (1 : 8 )
390+ cv1 = CategoricalArray (dv1, ordered= true )
391+
392+ d = Dataset (dv1= dv1, dv2= dv2, dv3= dv3, cv1= cv1)
393+ @test issorted (d, :cv1 )
394+ @test issorted (d, :dv1 )
395+ @test ! issorted (d, :dv2 )
396+
397+ ds = Dataset (x = [0xfffffffffffffff3 , 0xfffffffffffffff2 , 0xfffffffffffffff4 , 0xfffffffffffffff1 ], y = [1 ,1 ,2 ,2 ])
398+ @test issorted (ds[[4 ,2 ,1 ,3 ],:],1 )
399+ @test issorted (view (ds, [4 ,2 ,1 ,3 ], :), 1 )
400+ @test issorted (ds[[3 ,1 ,2 ,4 ],:],1 , rev = true )
401+ setformat! (ds, 1 => isodd)
402+ @test issorted (ds[[2 ,3 ,1 ,4 ],:],1 )
403+ @test issorted (view (ds, [2 ,3 ,1 ,4 ], :), 1 )
404+ @test issorted (ds[[1 ,4 ,2 ,3 ],:],1 , rev= true )
405+ @test issorted (ds[[2 ,3 ,1 ,4 ], :], 1 : 2 )
406+ @test issorted (view (ds, [2 ,3 ,1 ,4 ], :), 1 : 2 )
407+ @test issorted (ds[[3 ,2 ,4 ,1 ], :], 1 : 2 , rev = [false , true ])
408+ @test issorted (view (ds, [3 ,2 ,4 ,1 ], :), 1 : 2 , rev = [false , true ])
409+
410+
411+ x = rand (Int128, 1000 )
412+ y = rand (1 : 100 , 1000 )
413+ ds = Dataset (x = x, y = y)
414+ @test issorted (sort (ds, 1 ),1 )
415+ @test issorted (sort (ds, 1 , rev = true ), 1 , rev= true )
416+ setformat! (ds, 1 => isodd)
417+ @test issorted (sort (ds, 1 ),1 )
418+ @test issorted (sort (ds, 1 , rev = true ), 1 , rev = true )
419+
420+ ds = Dataset (x = big .([1 ,4 ,- 1 ,1 ,100 ]), x2 = [45 ,3 ,98 ,100 ,10 ])
421+ @test ! issorted (ds, 1 )
422+ @test issorted (ds[[3 ,1 ,4 ,2 ,5 ], 1 : 1 ], 1 )
423+ @test issorted (view (ds, [5 ,2 ,1 ,4 ,3 ], [2 ,1 ]), 2 , rev = true )
424+ @test issorted (ds[[3 , 1 , 4 , 2 , 5 ], :], 1 : 2 )
425+ @test issorted (ds[[3 ,4 ,1 ,2 ,5 ],:], 1 : 2 , rev = [false , true ])
426+ ds[2 ,1 ]= missing
427+ @test ! issorted (ds, 1 )
428+ @test issorted (ds[[3 ,1 ,4 ,5 ,2 ], :], 1 )
429+ @test issorted (view (ds, [2 ,5 ,1 ,4 ,3 ], :), 1 , rev = true )
430+
431+ for i in 1 : 100
432+ ds = Dataset (rand (1 : 10 , 1000 , 10 ), :auto )
433+ for j in 1 : 10
434+ @test issorted (sort (ds, 1 : j), 1 : j)
435+ @test issorted (sort (ds, 1 : j, rev = true ), 1 : j, rev = true )
436+ setformat! (ds, 1 : 10 => isodd)
437+ @test issorted (sort (ds, 1 : j), 1 : j)
438+ @test issorted (sort (ds, 1 : j, rev = true ), 1 : j, rev = true )
439+ end
440+ ds = Dataset (rand (1 : 10. , 1000 , 10 ), :auto )
441+ map! (ds, x-> rand ()< .1 ? missing : x, :)
442+ for j in 1 : 10
443+ @test issorted (sort (ds, 1 : j), 1 : j)
444+ @test issorted (sort (ds, 1 : j, rev = true ), 1 : j, rev = true )
445+ setformat! (ds, 1 : 10 => sign)
446+ @test issorted (sort (ds, 1 : j), 1 : j)
447+ @test issorted (sort (ds, 1 : j, rev = true ), 1 : j, rev = true )
448+ end
449+ ds = Dataset (rand (1 : 10. , 1000 , 10 ), :auto )
450+ map! (ds, x-> rand ()< .1 ? missing : x, :)
451+ for j in 1 : 10
452+ ds[! , j] = PooledArray (ds[! , j])
453+ end
454+ for j in 1 : 10
455+ @test issorted (sort (ds, 1 : j), 1 : j)
456+ @test issorted (sort (ds, 1 : j, rev = true ), 1 : j, rev = true )
457+ setformat! (ds, 1 : 10 => sign)
458+ @test issorted (sort (ds, 1 : j), 1 : j)
459+ @test issorted (sort (ds, 1 : j, rev = true ), 1 : j, rev = true )
460+ end
461+ end
462+ for i in 1 : 100
463+ ds = Dataset (rand (1 : 10 , 1000 , 10 ), :auto )
464+ for j in 1 : 10
465+ sort! (ds, 1 : j)
466+ issorted! (ds, 1 : j)
467+ @test IMD. _sortedcols (ds) == 1 : j
468+ @test issorted (ds, 1 : j)
469+
470+ setformat! (ds, 1 : 10 => isodd)
471+ sort! (ds, 1 : j, rev = true )
472+ issorted! (ds, 1 : j, rev = true )
473+ @test IMD. _sortedcols (ds) == 1 : j
474+ @test issorted (ds, 1 : j, rev = true )
475+ end
476+ ds = Dataset (rand (1 : 10. , 1000 , 10 ), :auto )
477+ map! (ds, x-> rand ()< .1 ? missing : x, :)
478+ for j in 1 : 10
479+ sort! (ds, 1 : 2 : j)
480+ issorted! (ds, 1 : 2 : j)
481+ @test IMD. _sortedcols (ds) == collect (1 : 2 : j)
482+ @test issorted (ds, 1 : 2 : j)
483+
484+ setformat! (ds, 1 : 10 => sign)
485+ sort! (ds, 1 : 2 : j, rev = true )
486+ issorted! (ds, 1 : 2 : j, rev = true )
487+ @test IMD. _sortedcols (ds) == collect (1 : 2 : j)
488+ @test issorted (ds, 1 : 2 : j, rev = true )
489+ end
490+ ds = Dataset (rand (1 : 10. , 1000 , 10 ), :auto )
491+ map! (ds, x-> rand ()< .1 ? missing : x, :)
492+ for j in 1 : 10
493+ ds[! , j] = PooledArray (ds[! , j])
494+ end
495+ for j in 1 : 10
496+ sort! (ds, 1 : 2 : j)
497+ issorted! (ds, 1 : 2 : j)
498+ @test IMD. _sortedcols (ds) == collect (1 : 2 : j)
499+ @test issorted (ds, 1 : 2 : j)
500+
501+ setformat! (ds, 1 : 10 => sign)
502+ sort! (ds, 1 : 2 : j, rev = true )
503+ issorted! (ds, 1 : 2 : j, rev = true )
504+ @test IMD. _sortedcols (ds) == collect (1 : 2 : j)
505+ @test issorted (ds, 1 : 2 : j, rev = true )
506+ end
507+ end
508+
509+ end
0 commit comments