From e229a33394ba9708dd895760eabc47e9dc659c92 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Wed, 13 Jan 2016 09:31:42 +0100 Subject: [PATCH] EXAMINE: Extend test for empty dataset and fix bug. Closes bug #46866 --- src/language/stats/examine.c | 36 +++++++++++++++++++++++---------- tests/language/stats/examine.at | 7 ++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/language/stats/examine.c b/src/language/stats/examine.c index 46863cad97..295fca1a4a 100644 --- a/src/language/stats/examine.c +++ b/src/language/stats/examine.c @@ -1532,6 +1532,25 @@ update_n (const void *aux1, void *aux2 UNUSED, void *user_data, const struct examine *examine = aux1; struct exploratory_stats *es = user_data; + bool this_case_is_missing = false; + /* LISTWISE missing must be dealt with here */ + if (!examine->missing_pw) + { + for (v = 0; v < examine->n_dep_vars; v++) + { + const struct variable *var = examine->dep_vars[v]; + + if (var_is_value_missing (var, case_data (c, var), examine->dep_excl)) + { + es[v].missing += weight; + this_case_is_missing = true; + } + } + } + + if (this_case_is_missing) + return; + for (v = 0; v < examine->n_dep_vars; v++) { struct ccase *outcase ; @@ -1588,7 +1607,7 @@ calculate_n (const void *aux1, void *aux2 UNUSED, void *user_data) struct casereader *reader; struct ccase *c; - if (examine->histogramplot) + if (examine->histogramplot && es[v].non_missing > 0) { /* Sturges Rule */ double bin_width = fabs (es[v].minimum - es[v].maximum) @@ -1655,7 +1674,7 @@ calculate_n (const void *aux1, void *aux2 UNUSED, void *user_data) } casereader_destroy (reader); - if (examine->calc_extremes > 0) + if (examine->calc_extremes > 0 && es[v].non_missing > 0) { assert (es[v].minima[0].val == es[v].minimum); assert (es[v].maxima[0].val == es[v].maximum); @@ -1815,15 +1834,6 @@ run_examine (struct examine *cmd, struct casereader *input) case_unref (c); } - /* Remove cases on a listwise basis if requested */ - if ( cmd->missing_pw == false) - input = casereader_create_filter_missing (input, - cmd->dep_vars, - cmd->n_dep_vars, - cmd->dep_excl, - NULL, - NULL); - for (reader = input; (c = casereader_read (reader)) != NULL; case_unref (c)) { @@ -1836,6 +1846,10 @@ run_examine (struct examine *cmd, struct casereader *input) { summary_report (cmd, i); + const size_t n_cats = categoricals_n_count (cmd->cats, i); + if (n_cats == 0) + continue; + if (cmd->disp_extremes > 0) extremes_report (cmd, i); diff --git a/tests/language/stats/examine.at b/tests/language/stats/examine.at index 29dab48ff2..d4540ba45d 100644 --- a/tests/language/stats/examine.at +++ b/tests/language/stats/examine.at @@ -615,7 +615,12 @@ BEGIN DATA. . END DATA. -EXAMINE /x PLOT=HISTOGRAM. +EXAMINE /x + PLOT=HISTOGRAM BOXPLOT NPPLOT SPREADLEVEL(1) ALL + /ID=x + /STATISTICS = DESCRIPTIVES EXTREME (5) ALL + /PERCENTILE=AEMPIRICAL + . ]) AT_CHECK([pspp -o pspp.csv examine.sps], [0], [ignore]) dnl Ignore output -- this is just a no-crash check. -- 2.30.2