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

[Bug] Config reads string as scientific notation unless explicitly wrapped in quotes #2599

Closed
CSCaudill opened this issue Mar 1, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@CSCaudill
Copy link

🐛 Bug

Description

When the config yaml file contains a string with all numeric values and an 'E' in the string (e.g., 1E234), it will read the string as scientific notation (1e+234). This occurs even if the structured config defines the field as string.

Checklist

  • [ X ] I checked on the latest version of Hydra
  • [ X ] I created a minimal repro (See this for tips).

To reproduce

A minimal example has been created in this repository.

A short summary to reproduce:

  1. Create a project with a config yaml file
  2. Within the config yaml, create a parameter with a string of all numbers and a single 'E' character (e.g., 123E456)
  3. Create an app script that loads the config and prints the parameter values
  4. Notice that the parameter created in step 2 was handled as a number in scientific notation (e.g., 123e+456)

This even occurs if a structured config store instance is created to enforce a schema that defines this parameter as a string. This can be found in the repo mentioned above.

** Stack trace/error message **
The output below can be obtained by cloning the previously mentioned repository and running python app.py

account:
  user: user_123
  password: '1e+234'

Expected Behavior

It would be expected that the schema defined within the structured config store instance would be enforced, and the string would not be converted to a number.

System information

  • Hydra Version : 1.3.2
  • Python version : 3.8.16
  • Virtual environment type and version : NA
  • Operating system : all

Additional context

Adding quotes around the value will prevent this from occurring, but our project has numerous config files with long alphanumeric strings as parameter values, and this only occurs when the value happens to be only numbers with a single 'E' character.

@CSCaudill CSCaudill added the bug Something isn't working label Mar 1, 2023
@omry
Copy link
Collaborator

omry commented Mar 4, 2023

This originates with OmegaConf attempting to represent floats better. Unfortunatelly this is not something that can be fixed without breaking compatibility for people depending floats being interpreted as floats automatically.

Here is some discussion and past attempts at making this better:
omry/omegaconf#838

@omry
Copy link
Collaborator

omry commented Mar 4, 2023

Closing this for now. Feel free to respond here.

@omry omry closed this as completed Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants