Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit d982046

Browse files
authored
Merge pull request #5 from mpewsey/empty-table-fix
Add fix for empty table
2 parents c47c70a + ea33da6 commit d982046

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

plsxml/data/galloping_empty.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version='1.0' encoding='windows-1252' standalone='yes'?>
2+
3+
<root>
4+
<creator application='PLS-CADD' version='' registereduser='' date='' time='' computer='' user='' project='' projectpath='' activeline='' coordinatesystem='' zone='' zonedsescription='' gridshift='' surveyfoot='' schemafile='' plsxmlver='1.0'/>
5+
<table plsname='Galloping Summary' tagname='galloping_summary' ncols='5' nrows='0' units='0' version='1' titledetail=''>
6+
</table>
7+
</root>

plsxml/data/loader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
galloping_zip=dict(
1616
file='galloping.zip',
1717
tables=None
18+
),
19+
galloping_empty=dict(
20+
file='galloping_empty.xml',
21+
tables=None
1822
)
1923
)
2024

plsxml/plsxml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def is_xml(p):
9999

100100
_print = self._print_func()
101101
valid_ext = {'.xml'} # Valid extensions
102-
excl_ext = re.compile('__MACOSX|\.') # Excluded regex expressions
102+
excl_ext = re.compile(r'__MACOSX|\.') # Excluded regex expressions
103103

104104
if tables is not None:
105105
if isinstance(tables, str):
@@ -213,7 +213,8 @@ def convert_type(data):
213213
else:
214214
self[k] = pd.DataFrame.from_dict(d)
215215
# Create new dataframe with columns in order.
216-
self[k] = self[k][list(d[0])].copy()
216+
if d:
217+
self[k] = self[k][list(d[0])].copy()
217218

218219
def table_summary(self):
219220
"""

plsxml/plsxml_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ def test_verbose():
5454
def test_load_data():
5555
for x in data_names():
5656
xml = load_data(x)
57+
58+
59+
def test_empty_table():
60+
path = data_path('galloping_empty')
61+
xml = PLSXML(path, verbose=True)
62+
assert len(xml.keys()) == 1

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[pytest]
2-
DJANGO_SETTINGS_MODULE = settings
2+
# DJANGO_SETTINGS_MODULE = settings
33
python_files = tests.py test_*.py *_test.py

0 commit comments

Comments
 (0)