From 9574a6c2bf65ddc8ef13d4e942833bc5d4b0d2e0 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 12 Aug 2022 11:58:33 -0700 Subject: [PATCH] intersecting pcomputes --- src/language/stats/ctables.c | 5 +- tests/language/stats/ctables.at | 129 +++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 5 deletions(-) diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index eed3a8e3c8..25908eb65d 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -1395,6 +1395,7 @@ ctables_destroy (struct ctables *ct) hmap_delete (&ct->postcomputes, &pc->hmap_node); free (pc); } + hmap_destroy (&ct->postcomputes); fmt_settings_uninit (&ct->ctables_formats); pivot_table_look_unref (ct->look); @@ -4239,6 +4240,8 @@ ctables_pcexpr_evaluate (const struct ctables_pcexpr_evaluate_ctx *ctx, case CTPO_CAT_NRANGE: case CTPO_CAT_SRANGE: + case CTPO_CAT_MISSING: + case CTPO_CAT_OTHERNM: { struct ctables_cell_value cv = { .category = ctables_find_category_for_postcompute (ctx->section->table->ctables->dict, ctx->cats, ctx->parse_format, e) @@ -4260,8 +4263,6 @@ ctables_pcexpr_evaluate (const struct ctables_pcexpr_evaluate_ctx *ctx, } case CTPO_CAT_NUMBER: - case CTPO_CAT_MISSING: - case CTPO_CAT_OTHERNM: case CTPO_CAT_SUBTOTAL: case CTPO_CAT_TOTAL: { diff --git a/tests/language/stats/ctables.at b/tests/language/stats/ctables.at index 388c61f1c1..03f14a66ae 100644 --- a/tests/language/stats/ctables.at +++ b/tests/language/stats/ctables.at @@ -13,8 +13,6 @@ dnl * THRU (numeric ranges) dnl * OTHERNM dnl - Date/time variables and values dnl - Test PCOMPUTE: -dnl * MISSING, OTHERNM -dnl * multi-dimensional (multiple CCT_POSTCOMPUTE in one cell) dnl * dates dnl - Summary functions: dnl * U-prefix for unweighted summaries. @@ -1609,6 +1607,7 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl AT_CLEANUP AT_SETUP([CTABLES PCOMPUTE]) +AT_KEYWORDS([postcompute]) AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) AT_DATA([ctables.sps], [[GET 'nhtsa.sav'. @@ -1679,6 +1678,131 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl ]) AT_CLEANUP +AT_SETUP([CTABLES PCOMPUTE - OTHERNM and MISSING]) +AT_KEYWORDS([postcompute]) +AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) +AT_DATA([ctables.sps], +[[GET 'nhtsa.sav'. +CTABLES + /PCOMPUTE &x=EXPR(OTHERNM) + /PCOMPUTE &y=EXPR(MISSING) + /PPROPERTIES &x LABEL='Drivers' + /PPROPERTIES &y LABEL='Missing Values 2' + /TABLE=qn1 BY qns3a + /CATEGORIES VARIABLES=qn1 [OTHERNM, 5, &x, SUBTOTAL='Valid Values', MISSING, SUBTOTAL='Missing Values', &y] +]]) +AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl + Custom Tables +╭──────────────────────────────────────────────────────────────────────────────────────────┬────────────╮ +│ │S3a. GENDER:│ +│ ├─────┬──────┤ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├──────────────────────────────────────────────────────────────────────────────────────────┼─────┼──────┤ +│ 1. How often do you usually drive a car or other motor vehicle? Every day │ 2305│ 2362│ +│ Several days a week │ 440│ 834│ +│ Once a week or less │ 125│ 236│ +│ Only certain times a year│ 58│ 72│ +│ Never │ 192│ 348│ +│ Drivers │ 2928│ 3504│ +│ Valid Values │ 3120│ 3852│ +│ Don't know │ 3│ 5│ +│ Refused │ 9│ 10│ +│ Missing Values │ 12│ 15│ +│ Missing Values 2 │ 12│ 15│ +╰──────────────────────────────────────────────────────────────────────────────────────────┴─────┴──────╯ +]) +AT_CLEANUP + +AT_SETUP([CTABLES PCOMPUTE - THRU]) +AT_KEYWORDS([postcompute]) +AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) +AT_DATA([ctables.sps], +[[GET 'nhtsa.sav'. +CTABLES + /PCOMPUTE &x=EXPR([1 THRU 2]) + /PCOMPUTE &y=EXPR([3 THRU 4]) + /PCOMPUTE &z=EXPR([5] + MISSING) + /PPROPERTIES &x LABEL='Frequent Drivers' + /PPROPERTIES &y LABEL='Infrequent Drivers' + /PPROPERTIES &z LABEL='Not Drivers or Missing' + /TABLE=qn1 BY qns3a + /CATEGORIES VARIABLES=qn1 [1 THRU 2, &x, 3 THRU 4, &y, SUBTOTAL='Drivers', 5, MISSING, &z] +]]) +AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl + Custom Tables +╭──────────────────────────────────────────────────────────────────────────────────────────┬────────────╮ +│ │S3a. GENDER:│ +│ ├─────┬──────┤ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├──────────────────────────────────────────────────────────────────────────────────────────┼─────┼──────┤ +│ 1. How often do you usually drive a car or other motor vehicle? Every day │ 2305│ 2362│ +│ Several days a week │ 440│ 834│ +│ Frequent Drivers │ 2745│ 3196│ +│ Once a week or less │ 125│ 236│ +│ Only certain times a year│ 58│ 72│ +│ Infrequent Drivers │ 183│ 308│ +│ Drivers │ 2928│ 3504│ +│ Never │ 192│ 348│ +│ Don't know │ 3│ 5│ +│ Refused │ 9│ 10│ +│ Not Drivers or Missing │ 204│ 363│ +╰──────────────────────────────────────────────────────────────────────────────────────────┴─────┴──────╯ +]) +AT_CLEANUP + +dnl I'm not sure that this is the correct behavior (see +dnl https://mail.gnu.org/archive/html/pspp-users/2022-07/msg00002.html) +dnl but at least this test will notify us if the behavior changes. +AT_SETUP([CTABLES intersecting PCOMPUTEs]) +AT_KEYWORDS([PCOMPUTE postcompute]) +AT_DATA([ctables.sps], +[[DATA LIST LIST NOTABLE/x y z. +WEIGHT by z. +FORMATS ALL (F1.0). +VARIABLE LEVEL x y (NOMINAL). +BEGIN DATA. +1 4 5 +1 5 2 +1 6 9 +2 4 2 +2 5 3 +2 6 4 +3 4 1 +3 5 6 +3 6 1 +END DATA. + +CTABLES + /PCOMPUTE &a = EXPR([1] + [2]) + /PCOMPUTE &b = EXPR([2] + [3]) + /PCOMPUTE &c = EXPR([4] * [5]) + /PCOMPUTE &d = EXPR([5] * [6]) + /TABLE x BY y + /CATEGORIES VARIABLES=x [1, &a, 2, &b, 3] + /CATEGORIES VARIABLES=y [4, &c, 5, &d, 6]. +]]) +AT_CHECK([pspp ctables.sps -O box=unicode], [0], +[[ Custom Tables +╭───────────┬─────────────────────────────────────╮ +│ │ y │ +│ ├─────┬─────────┬─────┬─────────┬─────┤ +│ │ 4 │[4] * [5]│ 5 │[5] * [6]│ 6 │ +│ ├─────┼─────────┼─────┼─────────┼─────┤ +│ │Count│ Count │Count│ Count │Count│ +├───────────┼─────┼─────────┼─────┼─────────┼─────┤ +│x 1 │ 5│ 10│ 2│ 18│ 9│ +│ [1] + [2]│ 7│ .│ 5│ .│ 13│ +│ 2 │ 2│ 6│ 3│ 12│ 4│ +│ [2] + [3]│ 3│ .│ 9│ .│ 5│ +│ 3 │ 1│ 6│ 6│ 6│ 1│ +╰───────────┴─────┴─────────┴─────┴─────────┴─────╯ +]]) +AT_CLEANUP + AT_SETUP([CTABLES CLABELS]) AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) AT_DATA([ctables.sps], @@ -1689,7 +1813,6 @@ CTABLES /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=OPPOSITE. CTABLES /TABLE AgeGroup BY qns3a /CLABELS ROWLABELS=LAYER. CTABLES /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=LAYER. ]]) -pwd AT_CHECK([pspp ctables.sps --table-look="$builddir"/all-layers.stt -O box=unicode -O width=120], [0], [dnl Custom Tables ╭───────────────────────┬────────────╮ -- 2.30.2