CTABLES: Fix issue with special case for SLABELS POSITION=ROW.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 25 Nov 2022 23:20:52 +0000 (15:20 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 26 Nov 2022 00:26:35 +0000 (16:26 -0800)
With SLABELS POSITION=ROW and stacked variables with different summaries,
values were shown in the wrong rows.  This fixes the problem.

Thanks to Frans Houweling for reporting the bug.

src/language/stats/ctables.c
tests/language/stats/ctables.at

index 565c8ce1db10cbd512683973ee3c90968f3f24d2..deac6e9755d9d6877927425327adf816f2ad2b53 100644 (file)
@@ -4889,7 +4889,7 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
                   {
                     int leaf = cell->axes[a].leaf;
                     if (a == t->summary_axis && !summary_dimension)
-                      leaf += j;
+                      leaf += specs->specs[j].axis_idx;
                     dindexes[n_dindexes++] = leaf;
                   }
 
index 57f854ec6337d7c23401934b5aee7fdad0ce178f..ddccbfe3a2b42c238feec75f85b5bacbef32720f 100644 (file)
@@ -1765,6 +1765,79 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
 ])
 AT_CLEANUP
 
+AT_SETUP([CTABLES SLABELS with stacking different summaries])
+AT_CHECK([ln $top_srcdir/tests/language/stats/nhtsa.sav . || cp $top_srcdir/tests/language/stats/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES
+    /VLABELS VARIABLES=ALL DISPLAY=NAME
+    /TABLE qn1 [COUNT] + qnd1 [MEAN] + qn17 [UCOUNT] BY qns3a
+    /SLABELS POSITION=ROW.
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+                         Custom Tables
+╭─────────────────────────────────────────────────┬───────────╮
+│                                                 │   QNS3A   │
+│                                                 ├────┬──────┤
+│                                                 │Male│Female│
+├─────────────────────────────────────────────────┼────┼──────┤
+│QN1  Every day                   Count           │2305│  2362│
+│                                 Unweighted Count│    │      │
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Several days a week         Count           │ 440│   834│
+│                                 Unweighted Count│    │      │
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Once a week or less         Count           │ 125│   236│
+│                                 Unweighted Count│    │      │
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Only certain times a year   Count           │  58│    72│
+│                                 Unweighted Count│    │      │
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Never                       Count           │ 192│   348│
+│                                 Unweighted Count│    │      │
+│                                 Mean            │    │      │
+├─────────────────────────────────────────────────┼────┼──────┤
+│qnd1 Count                                       │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Unweighted Count                            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Mean                                        │  46│    50│
+├─────────────────────────────────────────────────┼────┼──────┤
+│QN17 OR, something else          Count           │    │      │
+│                                 Unweighted Count│   1│     1│
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Beer                        Count           │    │      │
+│                                 Unweighted Count│ 817│   256│
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Light beer                  Count           │    │      │
+│                                 Unweighted Count│ 406│   214│
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Wine                        Count           │    │      │
+│                                 Unweighted Count│ 390│  1028│
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Wine coolers                Count           │    │      │
+│                                 Unweighted Count│  20│   117│
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Hard liquor or mixed drinks Count           │    │      │
+│                                 Unweighted Count│ 392│   496│
+│                                 Mean            │    │      │
+│    ╶────────────────────────────────────────────┼────┼──────┤
+│     Flavored malt drinks        Count           │    │      │
+│                                 Unweighted Count│  20│    63│
+│                                 Mean            │    │      │
+╰─────────────────────────────────────────────────┴────┴──────╯
+])
+AT_CLEANUP
+
 AT_SETUP([CTABLES simple totals])
 AT_CHECK([ln $top_srcdir/tests/language/stats/nhtsa.sav . || cp $top_srcdir/tests/language/stats/nhtsa.sav .])
 AT_DATA([ctables.sps],