Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Fixes

* Include all metadata fields when converting to dataframe or CSV

## 0.6.5

### Enhancements
Expand All @@ -18,6 +20,7 @@

### Fixes


## 0.6.4

### Enhancements
Expand Down
13 changes: 11 additions & 2 deletions unstructured/staging/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
"filename",
"page_number",
"url",
"sent_from",
"sent_to",
"subject",
"sender",
]


def convert_to_isd(elements: List[Element]) -> List[Dict[str, str]]:
def convert_to_isd(elements: List[Element]) -> List[Dict[str, Any]]:
"""Represents the document elements as an Initial Structured Document (ISD)."""
isd: List[Dict[str, str]] = []
for element in elements:
Expand All @@ -34,7 +38,7 @@ def convert_to_isd(elements: List[Element]) -> List[Dict[str, str]]:
return isd


def convert_to_dict(elements: List[Element]) -> List[Dict[str, str]]:
def convert_to_dict(elements: List[Element]) -> List[Dict[str, Any]]:
"""Converts a list of elements into a dictionary."""
return convert_to_isd(elements)

Expand Down Expand Up @@ -127,6 +131,11 @@ def convert_to_isd_csv(elements: List[Element]) -> str:
if key in TABLE_FIELDNAMES:
row[key] = value

if row.get("sent_from"):
row["sender"] = row.get("sent_from")
if type(row["sender"]) == list:
row["sender"] = row["sender"][0]

with io.StringIO() as buffer:
csv_writer = csv.DictWriter(buffer, fieldnames=TABLE_FIELDNAMES)
csv_writer.writeheader()
Expand Down