fn read(&self, file: &PathBuf) -> CsvResult<PointCollection<T>> {
        let no_data = &self.options.no_data;

        // Read csv
        let mut reader = ReaderBuilder::new()
            .delimiter(self.options.delimiter)
            .from_path(file)?;
        let header: StringRecord = reader.headers()?.clone();
        let header: Vec<_> = header.iter().collect();

        let id_index = match &self.id_column {
            Some(col) => Some(self.column_index(&header[..], &col)?),
            None => None,
        };

        let mut col_indices = vec![];
        for col in &self.columns {
            col_indices.push(self.column_index(&header[..], col)?)
        }

        let mut ids = vec![];
        let mut data: Vec<T> = vec![];
        for record in reader.records() {
            let rec = record?;
            if let Some(id_idx) = id_index {
                ids.push(rec.get(id_idx).unwrap().to_string());
            }
            for col in &col_indices {
                let str = rec.get(*col).unwrap();
                let val = if str == no_data {
                    T::nan()
                } else {
                    match T::from_str_radix(str, 10) {
                        Ok(v) => v,
                        Err(_e) => {
                            return Err(CsvError::ParseError(format!(
                                "Unable to parse value '{}' to float.",
                                str
                            )))
                        }
                    }
                };

                data.push(val);
            }
        }

        Ok(PointCollection::new(
            Points::from_raw(data, col_indices.len())?,
            if id_index.is_some() { Some(ids) } else { None },
        )?)
    }
/// Reads a CSV file and parses it into a PointCollection
Reads a CSV file and parses it into a PointCollection
Reads a CSV file and parses it into a PointCollection
fn read(&self, file: &PathBuf) -> CsvResult<PointCollection<T>> {
        let no_data = &self.options.no_data;
        // Read csv
        let mut reader = ReaderBuilder::new()
            .delimiter(self.options.delimiter)
            .from_path(file)?;
        let header: StringRecord = reader.headers()?.clone();
        let header: Vec<_> = header.iter().collect();
        let id_index = match &self.id_column {
            Some(col) => Some(self.column_index(&header[..], &col)?),
            None => None,
        };
        let mut col_indices = vec![];
        for col in &self.columns {
            col_indices.push(self.column_index(&header[..], col)?)
        }
        let mut ids = vec![];
        let mut data: Vec<T> = vec![];
        for record in reader.records() {
            let rec = record?;
            if let Some(id_idx) = id_index {
                ids.push(rec.get(id_idx).unwrap().to_string());
            }
            for col in &col_indices {
                let str = rec.get(*col).unwrap();
                let val = if str == no_data {
                    T::nan()
                } else {
                    match T::from_str_radix(str, 10) {
                        Ok(v) => v,
                        Err(_e) => {
                            return Err(CsvError::ParseError(format!(
                                "Unable to parse value '{}' to float.",
                                str
                            )))
                        }
                    }
                };
                data.push(val);
            }
        }
        Ok(PointCollection::new(
            Points::from_raw(data, col_indices.len())?,
            if id_index.is_some() { Some(ids) } else { None },
        )?)
    }
fn read ( & self , file : & PathBuf ) -> CsvResult < PointCollection < T > > { let no_data = & self . options . no_data ; // Read csv let mut reader = ReaderBuilder :: new ( ) . delimiter ( self . options . delimiter ) . from_path ( file ) ? ; let header : StringRecord = reader . headers ( ) ? . clone ( ) ; let header : Vec < _ > = header . iter ( ) . collect ( ) ; let id_index = match & self . id_column { Some ( col ) => Some ( self . column_index ( & header [ .. ] , & col ) ? ) , None => None , } ; let mut col_indices = vec ! [ ] ; for col in & self . columns { col_indices . push ( self . column_index ( & header [ .. ] , col ) ? ) } let mut ids = vec ! [ ] ; let mut data : Vec < T > = vec ! [ ] ; for record in reader . records ( ) { let rec = record ? ; if let Some ( id_idx ) = id_index { ids . push ( rec . get ( id_idx ) . unwrap ( ) . to_string ( ) ) ; } for col in & col_indices { let str = rec . get ( * col ) . unwrap ( ) ; let val = if str == no_data { T :: nan ( ) } else { match T :: from_str_radix ( str , 10 ) { Ok ( v ) => v , Err ( _e ) => { return Err ( CsvError :: ParseError ( format ! ( " " str ) ) ) } } } ; data . push ( val ) ; } } Ok ( PointCollection :: new ( Points :: from_raw ( data , col_indices . len ( ) ) ? , if id_index . is_some ( ) { Some ( ids ) } else { None } , ) ? ) }
Reads a CSV file and parses it into a PointCollection
Reads a CSV file and parses it into a PointCollection
&self
file
&PathBuf
&self
file
&PathBuf