Skip to content

Commit

Permalink
fix(rust): Fix a bug in floating regex handling used in CSV type infe…
Browse files Browse the repository at this point in the history
…rence (#5695)
  • Loading branch information
ghais committed Dec 2, 2022
1 parent bf3131d commit cd7a8db
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion polars/polars-io/src/csv/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ pub fn get_reader_bytes<R: Read + MmapBytesReader + ?Sized>(
}

static FLOAT_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^(\s*-?((\d*\.\d+)[eE]?[-\+]?\d*)|[-+]?inf|[-+]?NaN|\d+[eE][-+]\d+)$").unwrap()
Regex::new(r"^(\s*-?((\d*\.\d+)[eE]?[-\+]?\d*)|[-+]?inf|[-+]?NaN|[-+]?\d+[eE][-+]\d+)$")
.unwrap()
});

static INTEGER_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^\s*-?(\d+)$").unwrap());
Expand Down Expand Up @@ -624,6 +625,9 @@ mod test {
assert!(FLOAT_RE.is_match("-NaN"));
assert!(FLOAT_RE.is_match("-inf"));
assert!(FLOAT_RE.is_match("inf"));
assert!(FLOAT_RE.is_match("-7e-05"));
assert!(FLOAT_RE.is_match("7e-05"));
assert!(FLOAT_RE.is_match("+7e+05"));
}

#[test]
Expand Down

0 comments on commit cd7a8db

Please sign in to comment.