Skip to content

Commit

Permalink
csv: add scientific notation without dots
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 4, 2021
1 parent 33cd8d1 commit 0ca6ff8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions polars/polars-io/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,4 +1344,18 @@ A3,\"B4_\"\"with_embedded_double_quotes\"\"\",C4,4";

Ok(())
}

#[test]
fn test_scientific_floats() -> Result<()> {
let csv = r#"foo,bar
10000001,1e-5
10000002,.04
"#;
let file = Cursor::new(csv);
let df = CsvReader::new(file).finish()?;
assert_eq!(df.shape(), (2, 2));
assert_eq!(df.dtypes(), &[DataType::Int64, DataType::Float64]);

Ok(())
}
}
3 changes: 2 additions & 1 deletion polars/polars-io/src/csv_core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pub fn get_reader_bytes<R: Read + MmapBytesReader>(reader: &mut R) -> Result<Rea
}

lazy_static! {
static ref FLOAT_RE: Regex = Regex::new(r"^\s*-?((\d*\.\d+)[eE]?[-\+]?\d*)|inf|NaN$").unwrap();
static ref FLOAT_RE: Regex =
Regex::new(r"^\s*-?((\d*\.\d+)[eE]?[-\+]?\d*)|inf|NaN|\d+[eE][-+]\d+$").unwrap();
static ref INTEGER_RE: Regex = Regex::new(r"^\s*-?(\d+)$").unwrap();
static ref BOOLEAN_RE: Regex = RegexBuilder::new(r"^\s*(true)$|^(false)$")
.case_insensitive(true)
Expand Down

0 comments on commit 0ca6ff8

Please sign in to comment.