This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch active_release
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/active_release by this push:
     new 1b9fd9e  Inferring 2. as Float64 for issue #929 (#950) (#966)
1b9fd9e is described below

commit 1b9fd9e3fb2653236513bb7dda5aa2fa14d1d831
Author: Andrew Lamb <[email protected]>
AuthorDate: Tue Nov 23 13:24:32 2021 -0500

    Inferring 2. as Float64 for issue #929 (#950) (#966)
    
    Co-authored-by: Brian Rackle <[email protected]>
---
 arrow/src/csv/reader.rs | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arrow/src/csv/reader.rs b/arrow/src/csv/reader.rs
index 21924f7..4940ea2 100644
--- a/arrow/src/csv/reader.rs
+++ b/arrow/src/csv/reader.rs
@@ -60,7 +60,7 @@ use crate::record_batch::RecordBatch;
 use csv_crate::{ByteRecord, StringRecord};
 
 lazy_static! {
-    static ref DECIMAL_RE: Regex = Regex::new(r"^-?(\d*\.\d+)$").unwrap();
+    static ref DECIMAL_RE: Regex = 
Regex::new(r"^-?(\d*\.\d+|\d+\.\d*)$").unwrap();
     static ref INTEGER_RE: Regex = Regex::new(r"^-?(\d+)$").unwrap();
     static ref BOOLEAN_RE: Regex = RegexBuilder::new(r"^(true)$|^(false)$")
         .case_insensitive(true)
@@ -1343,8 +1343,7 @@ mod tests {
         assert_eq!(infer_field_schema("10"), DataType::Int64);
         assert_eq!(infer_field_schema("10.2"), DataType::Float64);
         assert_eq!(infer_field_schema(".2"), DataType::Float64);
-        // Should be parsed as Float or Int. See 
https://github.com/apache/arrow-rs/issues/929
-        assert_eq!(infer_field_schema("2."), DataType::Utf8);
+        assert_eq!(infer_field_schema("2."), DataType::Float64);
         assert_eq!(infer_field_schema("true"), DataType::Boolean);
         assert_eq!(infer_field_schema("false"), DataType::Boolean);
         assert_eq!(infer_field_schema("2020-11-08"), DataType::Date32);
@@ -1581,6 +1580,8 @@ mod tests {
         assert_eq!(Some(-12.34), parse_item::<Float64Type>("-12.34"));
         assert_eq!(Some(12.0), parse_item::<Float64Type>("12"));
         assert_eq!(Some(0.0), parse_item::<Float64Type>("0"));
+        assert_eq!(Some(2.0), parse_item::<Float64Type>("2."));
+        assert_eq!(Some(0.2), parse_item::<Float64Type>(".2"));
         assert!(parse_item::<Float64Type>("nan").unwrap().is_nan());
         assert!(parse_item::<Float64Type>("NaN").unwrap().is_nan());
         assert!(parse_item::<Float64Type>("inf").unwrap().is_infinite());

Reply via email to