Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Resolve excel database exporter bug #1106

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
9 changes: 5 additions & 4 deletions activity_browser/bwutils/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ def format_pedigree(data: dict) -> str:


def frmt_str(data: Union[str, dict]) -> str:
return format_pedigree(data) if isinstance(data, dict) else data
"""Format non-numerical data (like tuples) to string format."""
return format_pedigree(data) if isinstance(data, dict) else str(data)


def write_lci_excel(db_name: str, path: str, objs=None, sections=None) -> Path:
"""Export database `database_name` to an Excel spreadsheet.

Not all data can be exported. The following constraints apply:

* Nested data, e.g. `{'foo': {'bar': 'baz'}}` are excluded. Spreadsheets are not a great format for nested data. However, *tuples* are exported, and the characters `::` are used to join elements of the tuple.
* Nested data, e.g. `{'foo': {'bar': 'baz'}}` are excluded. Spreadsheets are not a great format for nested data.
However, *tuples* are exported, and the characters `::` are used to join elements of the tuple.
* The only well-supported data types are strings, numbers, and booleans.

Returns the filepath of the exported file.
Expand Down Expand Up @@ -100,8 +102,7 @@ def write_lci_excel(db_name: str, path: str, objs=None, sections=None) -> Path:
elif isinstance(value, numbers.Number):
sheet.write_number(row_index, col_index, value, frmt(value))
else:
sheet.write(row_index, col_index, value, frmt(value))
# sheet.write_string(row_index, col_index, frmt_str(value), frmt(value))
sheet.write_string(row_index, col_index, frmt_str(value), frmt(value))

workbook.close()

Expand Down