Skip to content

Commit 096a3ec

Browse files
committed
tweaks
1 parent e5bd0f6 commit 096a3ec

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

datamule/datamule/tables/tables.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,22 @@ def apply_mapping(flattened_data, mapping_dict, accession, must_exist_in_mapping
9595

9696

9797
class Table:
98-
def __init__(self, data, name, accession, description=None, preamble=None, footnotes=None, postamble=None):
99-
self.data = data
100-
if data != []:
98+
def __init__(self, data_raw, name, accession, description=None, preamble=None, footnotes=None, postamble=None):
99+
self.data_raw = data_raw
100+
101+
# Clean the data - strip dict wrappers and keep just table content
102+
if data_raw != []:
101103
try:
102-
self.columns = data[0].keys() # handle xml tables
104+
# Handle xml tables - already list of dicts
105+
self.columns = data_raw[0].keys()
106+
self.data = data_raw
103107
except:
104-
self.columns = data[0] # handle html tables
108+
# Handle html tables - already list of lists
109+
self.columns = data_raw[0]
110+
self.data = data_raw
111+
else:
112+
self.columns = []
113+
self.data = []
105114

106115
self.name = name
107116
self.accession = accession
@@ -122,8 +131,7 @@ def __str__(self):
122131

123132
# Preamble
124133
if self.preamble:
125-
preamble_texts = [item.get('text') or item.get('textsmall', '') for item in self.preamble]
126-
parts.append(f"\nPreamble: {' '.join(preamble_texts)}")
134+
parts.append(f"\nPreamble: {self.preamble}")
127135

128136
# The actual table
129137
formatted_table = _format_table(self.data)
@@ -135,15 +143,11 @@ def __str__(self):
135143

136144
# Footnotes
137145
if self.footnotes:
138-
parts.append("\nFootnotes:")
139-
for footnote in self.footnotes:
140-
footnote_text = footnote.get('text') or footnote.get('textsmall', '')
141-
parts.append(f" {footnote['footnote_id']}: {footnote_text}")
146+
parts.append(f"\nFootnotes: {self.footnotes}")
142147

143148
# Postamble
144149
if self.postamble:
145-
postamble_texts = [item.get('text') or item.get('textsmall', '') for item in self.postamble]
146-
parts.append(f"\nPostamble: {' '.join(postamble_texts)}")
150+
parts.append(f"\nPostamble: {self.postamble}")
147151

148152
return '\n'.join(parts)
149153

@@ -176,7 +180,7 @@ def parse_tables(self, data, must_exist_in_mapping=True):
176180
def add_table(self, data, name, description=None, preamble=None, footnotes=None, postamble=None):
177181
"""Add a table with optional metadata components"""
178182
self.tables.append(Table(
179-
data=data,
183+
data_raw=data,
180184
name=name,
181185
accession=self.accession,
182186
description=description,

datamule/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
setup(
3333
name="datamule",
3434
author="John Friedman",
35-
version="3.2.6",
35+
version="3.2.7",
3636
description="Work with SEC submissions at scale.",
3737
packages=find_packages(include=['datamule', 'datamule.*']),
3838
url="https://github.com/john-friedman/datamule-python",

0 commit comments

Comments
 (0)