@@ -540,6 +540,60 @@ const data3 = {
540540 table . delete ( ) ;
541541 } ) ;
542542
543+ test ( "group by with multiple hidden sorts emits all visible columns in to_columns()" , async function ( ) {
544+ // https://github.com/perspective-dev/perspective/issues/3195
545+ const table = await perspective . table ( {
546+ v1 : [ 1 , 2 , 3 , 4 ] ,
547+ v2 : [ 10 , 20 , 30 , 40 ] ,
548+ v3 : [ 100 , 200 , 300 , 400 ] ,
549+ h1 : [ 1.5 , 2.5 , 3.5 , 4.5 ] ,
550+ h2 : [ 4.5 , 3.5 , 2.5 , 1.5 ] ,
551+ g : [ "a" , "a" , "b" , "b" ] ,
552+ } ) ;
553+ const view = await table . view ( {
554+ columns : [ "v1" , "v2" , "v3" ] ,
555+ group_by : [ "g" ] ,
556+ sort : [
557+ [ "h1" , "desc" ] ,
558+ [ "h2" , "desc" ] ,
559+ ] ,
560+ } ) ;
561+ const result = await view . to_columns ( ) ;
562+ expect ( result ) . toEqual ( {
563+ __ROW_PATH__ : [ [ ] , [ "b" ] , [ "a" ] ] ,
564+ v1 : [ 10 , 7 , 3 ] ,
565+ v2 : [ 100 , 70 , 30 ] ,
566+ v3 : [ 1000 , 700 , 300 ] ,
567+ } ) ;
568+ view . delete ( ) ;
569+ table . delete ( ) ;
570+ } ) ;
571+
572+ test ( "group by with more hidden sorts than visible columns does not emit hidden columns in to_columns()" , async function ( ) {
573+ // https://github.com/perspective-dev/perspective/issues/3195
574+ const table = await perspective . table ( {
575+ v1 : [ 1 , 2 , 3 , 4 ] ,
576+ h1 : [ 1.5 , 2.5 , 3.5 , 4.5 ] ,
577+ h2 : [ 4.5 , 3.5 , 2.5 , 1.5 ] ,
578+ g : [ "a" , "a" , "b" , "b" ] ,
579+ } ) ;
580+ const view = await table . view ( {
581+ columns : [ "v1" ] ,
582+ group_by : [ "g" ] ,
583+ sort : [
584+ [ "h1" , "desc" ] ,
585+ [ "h2" , "desc" ] ,
586+ ] ,
587+ } ) ;
588+ const result = await view . to_columns ( ) ;
589+ expect ( result ) . toEqual ( {
590+ __ROW_PATH__ : [ [ ] , [ "b" ] , [ "a" ] ] ,
591+ v1 : [ 10 , 7 , 3 ] ,
592+ } ) ;
593+ view . delete ( ) ;
594+ table . delete ( ) ;
595+ } ) ;
596+
543597 test ( "split by ['y']" , async function ( ) {
544598 const table = await perspective . table ( data ) ;
545599 const view = await table . view ( {
0 commit comments