variable: Also complain about negative weights in var_force_valid_weight().
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 28 Aug 2022 21:14:56 +0000 (14:14 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 28 Aug 2022 21:22:19 +0000 (14:22 -0700)
src/data/variable.c

index 8acac77fb2072a937207f627d92b4b1fd584c4c6..8867ba4baed33775545cb1efedd943d668fd8da0 100644 (file)
@@ -1326,15 +1326,16 @@ var_clear_vardict (struct variable *v)
 double
 var_force_valid_weight (const struct variable *wv, double w, bool *warn_on_invalid)
 {
-  if (w < 0.0 || (wv && var_is_num_missing (wv, w)))
-    w = 0.0;
-
-  if (w == 0.0 && warn_on_invalid != NULL && *warn_on_invalid)
+  if (w <= 0.0 || (wv ? var_is_num_missing (wv, w) : w == SYSMIS))
     {
-      *warn_on_invalid = false;
-      msg (SW, _("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."));
+      w = 0.0;
+      if (warn_on_invalid != NULL && *warn_on_invalid)
+        {
+          *warn_on_invalid = false;
+          msg (SW, _("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."));
+        }
     }
 
   return w;