FREQUENCIES: Warn the user if any weight values are missing.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 27 Apr 2019 11:31:07 +0000 (13:31 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 27 Apr 2019 11:31:07 +0000 (13:31 +0200)
NEWS
src/language/stats/frequencies.c
tests/language/stats/frequencies.at

diff --git a/NEWS b/NEWS
index c252290add5267fedb96d3360b17ae0206b9d42f..d5e8ee0d22a9275ff302ecd981a994ca0e2244cd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ Please send PSPP bug reports to bug-gnu-pspp@gnu.org.
 
 Changes from 1.2.0 to 1.3.0:
 
+ * FREQUENCIES will emit a warning if one or more weight values are missing.
+
  * Plain text output is no longer divided into pages, since it is now
    rarely printed on paper.
 
index 8bd6c600205d3fe75dc6a99dd230c2ab9591146b..c96b4eab190efb7d6872f5d20d2e82a994f6cf91 100644 (file)
@@ -225,6 +225,8 @@ struct frq_proc
 
     /* Histogram and pie chart settings. */
     struct frq_chart *hist, *pie, *bar;
+
+    bool warn;
   };
 
 
@@ -469,7 +471,7 @@ cleanup_freq_tab (struct var_freqs *vf)
 static void
 calc (struct frq_proc *frq, const struct ccase *c, const struct dataset *ds)
 {
-  double weight = dict_get_case_weight (dataset_dict (ds), c, NULL);
+  double weight = dict_get_case_weight (dataset_dict (ds), c, &frq->warn);
   size_t i;
 
   for (i = 0; i < frq->n_vars; i++)
@@ -613,6 +615,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
   frq.hist = NULL;
   frq.pie = NULL;
   frq.bar = NULL;
+  frq.warn = true;
 
 
   /* Accept an optional, completely pointless "/VARIABLES=" */
index ca0467264e84a7f63abf8cec3cc40a846c0129e5..141c36fd8331e97e4ef558d9bd39cd58d08d4535 100644 (file)
@@ -845,3 +845,44 @@ FREQUENCIES VARIABLES=SCORE
 AT_CHECK([pspp bug.sps], [0],  [ignore])
 
 AT_CLEANUP
+
+
+AT_SETUP([FREQUENCIES vs. missing weights])
+AT_DATA([warn.sps], [dnl
+data list notable list /x w .
+begin data.
+1 1
+2 1
+1 1
+3 1
+3 .
+4 .
+end data.
+
+weight by w.
+
+frequencies /variables=x.
+])
+
+AT_CHECK([pspp warn.sps -O format=csv], [0],  [dnl
+"warn.sps:13: warning: FREQUENCIES: At least one case in the data file had a weight value that was user-missing, system-missing, zero, or negative.  These case(s) were ignored."
+
+Table: Statistics
+,,x
+N,Valid,4.00
+,Missing,.00
+Mean,,1.75
+Std Dev,,.96
+Minimum,,1.00
+Maximum,,4.00
+
+Table: x
+,,Frequency,Percent,Valid Percent,Cumulative Percent
+Valid,1.00,2.00,50.0%,50.0%,50.0%
+,2.00,1.00,25.0%,25.0%,75.0%
+,3.00,1.00,25.0%,25.0%,100.0%
+,4.00,.00,.0%,.0%,100.0%
+Total,,4.00,100.0%,,
+])
+
+AT_CLEANUP