cleanup
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 3 Jan 2026 19:48:40 +0000 (11:48 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 3 Jan 2026 19:48:40 +0000 (11:48 -0800)
rust/pspp/src/spv/read/legacy_xml.rs

index cd539d61f428402fb5e8f4ba003419170d859cd4..9c60440867ebbdbd2c0e9180c42ea21a3cc3dab8 100644 (file)
@@ -48,9 +48,7 @@ use crate::{
 #[derive(Clone, Debug)]
 pub struct DataValue {
     /// Optional index.
-    ///
-    /// This is always `None` as initially decoded.
-    pub index: Option<f64>,
+    pub index: Option<usize>,
 
     /// Data value.
     pub value: Datum<String>,
@@ -61,7 +59,6 @@ impl DataValue {
     /// there is one, falling back to the index.
     pub fn category(&self) -> Option<usize> {
         self.index
-            .and_then(|v| (v >= 0.0 && v < usize::MAX as f64).then_some(v as usize))
     }
 
     /// Interprets this data value as a [Format], first by looking it up in
@@ -904,7 +901,10 @@ impl SourceVariable {
             values
                 .iter()
                 .map(|value| DataValue {
-                    index: value.as_number().flatten(),
+                    index: value
+                        .as_number()
+                        .flatten()
+                        .and_then(|v| (v >= 0.0 && v < usize::MAX as f64).then_some(v as usize)),
                     value: value.clone(),
                 })
                 .collect()
@@ -979,7 +979,7 @@ impl DerivedVariable {
             if let Some(n_values) = series_len(series) {
                 (0..n_values)
                     .map(|_| DataValue {
-                        index: Some(0.0),
+                        index: Some(0),
                         value: Datum::Number(Some(0.0)),
                     })
                     .collect()
@@ -1002,11 +1002,6 @@ impl DerivedVariable {
             });
             vec![]
         };
-        for datum in &mut values {
-            if let Datum::Number(Some(number)) = &datum.value {
-                datum.index = Some(*number);
-            }
-        }
         Map::from_vmes(&self.value_map).apply(&mut values);
         if let Some(format) = &self.format {
             Map::from_format(format).apply(&mut values);