Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove scientific notation when converting floats to strings. #983

Closed
alexhallam opened this issue Nov 26, 2021 · 6 comments
Closed

Remove scientific notation when converting floats to strings. #983

alexhallam opened this issue Nov 26, 2021 · 6 comments
Labels
question Further information is requested

Comments

@alexhallam
Copy link

Which part is this question about
parquet

Describe your question
I would like to get a string of the values, but not in scientific notation (if 0.01 then return "0.01" not "1E-2").

Additional context

I am trying to read parquets and print the output, but the fact that conversion to string results in a scientific notation is making the task harder for me. I am guessing there is a simple way to make sure I get the full value without conversion to scientific notation, but I have not found a method for that yet.

I have a snippet of code below showing the general idea.

image

@alexhallam alexhallam added the question Further information is requested label Nov 26, 2021
@alamb
Copy link
Contributor

alamb commented Dec 8, 2021

Instead of calling c.1.to_string() perhaps you could use something like this (untested):

match c.1 {
  Field::Float(f) => format!("{}", f), // or however else you wanted to format floats 
  Feld::Double(f) => format!("{}", f), // or however else you wanted to format floats 
  _ => c.1.to_string()
}

@alexhallam
Copy link
Author

Thanks. I will give this a try.

@alexhallam
Copy link
Author

alexhallam commented Feb 9, 2022

I am getting an error with the code below

    fn pull_rows(row: &parquet::record::Row) -> Vec<std::string::String> {
        row.get_column_iter()
            .map(|c: (&String, &Field)| match c.1 {
                Field::Float(f) => format!("{}", f),
                Field::Double(f) => format!("{}", f),
                _ => c.1.to_string(),
            })
            .collect::<Vec<_>>()
    }

here is the error

error[E0599]: no associated item named `Float` found for struct `arrow::datatypes::Field` in the current scope
   --> src/main.rs:292:24
    |
292 |                 Field::Float(f) => format!("{}", f), // or however else you wanted to format floats
    |                        ^^^^^ associated item not found in `arrow::datatypes::Field`

error[E0599]: no associated item named `Double` found for struct `arrow::datatypes::Field` in the current scope
   --> src/main.rs:293:24
    |
293 |                 Field::Double(f) => format!("{}", f), // or however else you wanted to format floats
    |                        ^^^^^^ associated item not found in `arrow::datatypes::Field`

Since Field::Float does not exist I am guessing I will need to do something like a f.data_type as shown here https://docs.rs/arrow/3.0.0/arrow/datatypes/struct.Field.html

@alamb
Copy link
Contributor

alamb commented Feb 9, 2022

@alexhallam I think the issue is that you are using the "wrong" Field -- the error message is for one.in Arrow and the one you probably need to use is in parquet: https://docs.rs/parquet/8.0.0/parquet/record/enum.Field.html

@alexhallam
Copy link
Author

That fixed the issue. Thanks

@alamb alamb closed this as completed Feb 10, 2022
@alamb
Copy link
Contributor

alamb commented Feb 10, 2022

Glad you figured out the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants