kinverarity1 / lasio

Python library for reading and writing well data using Log ASCII Standard (LAS) files
https://lasio.readthedocs.io/en/latest/
MIT License
345 stars 151 forks source link

PEP 0515 (Underscores in Numeric Literals) not taken into account when reading headers. #592

Open Aycon3296 opened 8 months ago

Aycon3296 commented 8 months ago

Describe the error Underscores are accepted as numbers when reading service sections.

For playback Try to read any title that contains an underscore. For example "WELL" header item in:

~Version Information
#---------------------------------------------------------------- ---------------
VERS. 1.20: CWLS log ASCII Standard - VERSION 1.20
WRAP. YES : Multiple lines per depth step
~Well Information
#---------------------------------------------------------------- ---------------
#MNEM.UNIT DATA TYPE INFORMATION
#--------- -------------------------- -------------- ---------
STRT .M 74 : Start depth
STOP .M 1855 : Stop depth
STEP .M 0.2000 : Step
NULL. -9999 : Null value
COMP. COMPANY: Test
WELL. WELL: 321_04

Expected Behavior The title will be read as a string with underscores, but not as a number.

Software Versions (fill in the following information):

Additional context Due to https://www.python.org/dev/peps/pep-0515/ numbers containing underscores are now considered real numbers. So if you use int(value) inside a try/catch block to check whether the message read is a number, you will run into problems parsing strings like this "WELL . WELL : 32104" (In "~W" sections). You could check for "_" signs in the read fragment before doing this. And if the "\" signs are present, then conclude that the fragment read is str instead of int.

kinverarity1 commented 8 months ago

Sounds good, I would welcome a PR but it should be configurable and off by default. I would not expect that to be parsed as a number, but accept that some might.