Skip to content

Commit

Permalink
Directory Parse warning (#64)
Browse files Browse the repository at this point in the history
* added warning to directory parse

added logging warning to parse_directory so that it will print out files that cannot be opened by lasio. It then moves on to the next file in the directory and parses that one.

* Update keyword_tree.py

* added empty las file and test for logging warning

added an empty las file (nothing inside the file at all) that will cause lasio read issues which in turn should call the logging warning in parse_directory. New test catches that warning
  • Loading branch information
jessepisel authored Mar 24, 2021
1 parent 52b98d7 commit 9596312
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Empty file added alaska/data/testcase6.LAS
Empty file.
8 changes: 7 additions & 1 deletion alaska/keyword_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os.path
import gzip
import json
import logging

import pandas as pd
import seaborn as sns
Expand Down Expand Up @@ -266,8 +267,13 @@ def parse_directory(self, directory):
comprehensive_dict = {}
comprehensive_not_found = []
for filename in os.listdir(directory):
if filename.endswith((".LAS",".las")):
if filename.endswith((".LAS", ".las")):
path = os.path.join(directory, filename)
try:
las = lasio.read(path)
except:
logging.warning(f"lasio was not able to read {filename}")
continue
las = lasio.read(path)
mnem, desc = [], []
for key in las.keys():
Expand Down
10 changes: 10 additions & 0 deletions alaska/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from pathlib import Path
import matplotlib.pyplot as plt
import pytest
import logging
from ..keyword_tree import Alias, search, make_tree, search_child, Node
from ..predict_from_model import make_prediction
from ..get_data_path import get_data_path
Expand Down Expand Up @@ -208,6 +209,15 @@ def test_parse_directory_3():
assert len(aliased.keys()) > 0


def test_parse_directory_4(caplog):
"""
Test that Alias class returns a warning for empty LAS file
"""
aliaser = Alias()
aliaser.parse_directory(test_dir_1)
assert "lasio was not able to read testcase6.LAS" in caplog.text


def test_dictionary_parse_1():
"""
Test that dictionary parser in Aliaser parses and returns correct labels
Expand Down

0 comments on commit 9596312

Please sign in to comment.