Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix #473 - parse header lines with no period #474

Merged
merged 2 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lasio/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,17 +918,32 @@ def configure_metadata_patterns(line, section_name):
unit_re = r"(?P<unit>([0-9]+\s)?[^\s]*)"

# Alternate regular expressions for special cases
name_missing_period_re = r"(?P<name>[^:]*):"
value_missing_period_re = r"(?P<value>.*)"
value_without_colon_delimiter_re = r"(?P<value>[^:]*)"
value_with_time_colon_re = (
r"(?P<value>.*?)(?:(?<!( [0-2][0-3]| hh| HH)):(?!([0-5][0-9]|mm|MM)))"
)
name_with_dots_re = r"\.?(?P<name>[^.].*[.])\."
no_desc_re = ""
no_unit_re = ""

# Configure special cases
# 1. missing colon delimiter and description field
# 2. double_dots '..' caused by mnemonic abbreviation (with period)
# 1. missing period (assume that only name and value are present)
# 2. missing colon delimiter and description field
# 3. double_dots '..' caused by mnemonic abbreviation (with period)
# next to the dot delimiter.
if ":" in line:
if not "." in line[:line.find(":")]:
# If there is no period, then we assume that the colon exists and
# everything on the left is the name, and everything on the right
# is the value - therefore no unit or description field.
name_re = name_missing_period_re
value_re = value_missing_period_re
desc_re = no_desc_re
unit_re = no_unit_re
value_with_time_colon_re = value_missing_period_re

if not ":" in line:
# If there isn't a colon delimiter then there isn't
# a description field either.
Expand Down
25 changes: 25 additions & 0 deletions tests/test_read_header_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,28 @@ def test_unit_with_space():
assert result["unit"] == "1000 lbf"
assert result["value"] == ""
assert result["descr"] == "(RT)"


def test_line_without_period():
line = " DRILLED :12/11/2010"
result = read_header_line(line)
assert result["name"] == "DRILLED"
assert result["value"] == "12/11/2010"

def test_line_without_period_with_space():
line = " PERM DAT :1"
result = read_header_line(line)
assert result["name"] == "PERM DAT"
assert result["value"] == "1"

def test_line_without_period_with_colon():
line = " TIME :14:00:32"
result = read_header_line(line)
assert result["name"] == "TIME"
assert result["value"] == "14:00:32"

def test_line_without_period_with_decimal_value():
line = " HOLE DIA :85.7"
result = read_header_line(line)
assert result["name"] == "HOLE DIA"
assert result["value"] == "85.7"