Added error handler.

[?]
CrEcTsRjb1hHQjHuumqRfqdbVV4X58iLEubi4noaDPFa
Aug 3, 2021, 5:41 AM
X2POHOVL2YB5G4GQZ3NO2HRFBZV3ANDWUIZW34GQXEI56AXSHO3AC

Dependencies

  • [2] NLFSLCBO Added in-place mut_range() and range().
  • [3] QYLGEDIV First record.
  • [4] XCCNAGMZ Created with_range() fn on RegularTimeSeries.
  • [5] YMV7RPQ5 Improved csv reading and cleanup up serialization.
  • [6] TD7KX2PI Added year-on-year transform.
  • [7] XIWTRGR6 Prepare to make external iterator for TimeSeries.
  • [8] VGDNIY33 Added error source locations.
  • [9] IYW574EK Created RegularTimeSeriesIter.

Change contents

  • edit in src/lib.rs at line 1
    [3.57][3.0:128](),[3.16][3.0:128](),[3.128][3.45:46](),[3.45][3.45:46](),[3.46][3.58:62]()
    //! A time-series abstraction. A date of with granularity in months or larger associated with a
    //! numeric array of any size.
    ///
  • replacement in src/lib.rs at line 20
    [3.64][2.0:43]()
    /// A duration between two `MonthlyDates`.
    [3.64]
    [2.43]
    /// A duration between two `Months`.
  • edit in src/lib.rs at line 49
    [3.359]
    [2.91]
    impl fmt::Display for Duration {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    let mut s = String::new();
    match self.0 {
    1 => s.push_str("1 month"),
    n => {
    s.push_str(&n.to_string());
    s.push_str(" months");
    },
    };
    write!(f, "{}", s)
    }
    }
  • replacement in src/lib.rs at line 192
    [3.659][3.659:764](),[3.764][2.381:435]()
    let year = match line[..4].parse() {
    Ok(y) => y,
    Err(_) => {
    return Err(parse_csv_date_failed(
    [3.659]
    [3.307]
    let year = line[..4].parse()
    .map_err(|_| {
    parse_csv_date_failed(
  • replacement in src/lib.rs at line 200
    [3.463][3.463:486](),[3.486][3.840:874](),[3.840][3.840:874]()
    ))
    },
    };
    [3.463]
    [3.874]
    )
    })?;
  • replacement in src/lib.rs at line 203
    [3.875][3.875:982](),[3.982][2.436:490]()
    let month = match line[5..7].parse() {
    Ok(m) => m,
    Err(_) => {
    return Err(parse_csv_date_failed(
    [3.875]
    [3.544]
    let month = line[5..7].parse()
    .map_err(|_| {
    parse_csv_date_failed(
  • replacement in src/lib.rs at line 211
    [3.700][3.700:723](),[3.723][3.1058:1092](),[3.1058][3.1058:1092]()
    ))
    },
    };
    [3.700]
    [3.1092]
    )
    })?;
  • replacement in src/lib.rs at line 214
    [3.1093][3.1093:1215](),[3.1215][2.491:546]()
    let value = match line[12..].parse::<f32>() {
    Ok(value) => value,
    Err(_) => {
    return Err(parse_csv_value_failed(
    [3.1093]
    [3.782]
    let value = line[12..].parse::<f32>()
    .map_err(|_| {
    parse_csv_value_failed(
  • replacement in src/lib.rs at line 222
    [3.938][3.938:961](),[3.961][3.1292:1326](),[3.1292][3.1292:1326]()
    ))
    },
    };
    [3.938]
    [3.1326]
    )
    })?;
  • edit in src/lib.rs at line 236
    [3.3969][3.1239:1643](),[3.1643][3.4253:4254](),[3.4253][3.4253:4254]()
    // /// Return true if the durations between Points are all equal.
    // pub fn is_regular(&self, duration: &MonthlyDate) -> bool {
    // if self.len < 2 {
    // return false
    // } else {
    // self.0.as_slice().windows(2).all(|datapoint_pair| {
    // datapoint_pair[1].date() - datapoint_pair[0].date() == *duration
    // })
    // }
    // }
  • replacement in src/lib.rs at line 238
    [3.1706][3.1706:1715]()
    [3.1706]
    [3.962]
  • replacement in src/lib.rs at line 360
    [3.2820][3.2727:2811](),[3.591][3.2727:2811]()
    pub fn zip_one_one(self, other: RegularTimeSeries<1>) -> RegularTimeSeries<2> {
    [3.2820]
    [3.667]
    pub fn zip_one_one(self, other: RegularTimeSeries<1>) -> Result<RegularTimeSeries<2>, Error> {
  • replacement in src/lib.rs at line 365
    [3.828][3.828:889]()
    if self.duration() != other.duration() { panic!() };
    [3.828]
    [3.889]
    if self.duration() != other.duration() {
    return Err(expected_same_durations(
    file!(),
    line!(),
    &self.duration().to_string(),
    &other.duration().to_string(),
    ));
    };
  • replacement in src/lib.rs at line 390
    [3.2901][3.1488:1540](),[3.1488][3.1488:1540]()
    TimeSeries::<2>::new(v).try_into().unwrap()
    [3.2901]
    [3.1540]
    TimeSeries::<2>::new(v).try_into()
  • edit in src/lib.rs at line 476
    [3.1650][3.3526:3527](),[3.3526][3.3526:3527]()
  • edit in src/lib.rs at line 477
    [3.3602][3.3602:3603]()
  • edit in src/lib.rs at line 486
    [3.1793]
    [3.3903]
    let index = (date.as_isize() - self.first_date().as_isize()) / self.duration.0;
  • edit in src/lib.rs at line 488
    [3.3904][3.3904:3990](),[3.3990][3.1550:1551](),[3.5366][3.1550:1551]()
    let index = date.as_isize() - self.first_date().as_isize() / self.duration.0;
  • edit in src/lib.rs at line 579
    [3.5573][3.5573:5574]()
  • edit in src/lib.rs at line 582
    [3.5760][3.5760:5761]()
  • edit in src/lib.rs at line 722
    [3.10469]
  • replacement in src/error.rs at line 30
    [3.2716][3.2716:2720]()
    ///
    [3.2716]
    [3.2039]
    pub fn expected_same_durations(
    code_file: &str,
    code_line: u32,
    first_duration: &str,
    second_duration: &str) -> Error
    {
    Error(format!(
    "[time_series:02:{}:{}] Expected time-series to have same duration but had [{}] and [{}].",
    code_file,
    code_line,
    first_duration,
    second_duration,
    ))
    }