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

Scenario loading bugfix + Better error message on missing keys #743

Merged
5 changes: 4 additions & 1 deletion activity_browser/bwutils/superstructure/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ def get_header_index(document_path: Union[str, Path], import_sheet: int):
for i in range(10):
value = sheet.cell(i + 1, 1).value
if isinstance(value, str) and value.startswith("from activity name"):
wb.close()
return i
except IndexError as e:
wb.close()
raise IndexError("Expected headers not found in file").with_traceback(e.__traceback__)
except UnicodeDecodeError as e:
print("Given document uses an unknown encoding: {}".format(e))
wb.close()
raise ValueError("Could not find required headers in given document sheet.")


Expand All @@ -56,7 +59,7 @@ def import_from_excel(document_path: Union[str, Path], import_sheet: int = 1):

Any '*' character used at the start of a row or will cause that row
to be excluded from the import.
A '#' charater at the start of a column will cause that column to be
A '#' character at the start of a column will cause that column to be
excluded from the import.

'usecols' is used to exclude specific columns from the excel document.
Expand Down
4 changes: 3 additions & 1 deletion activity_browser/bwutils/superstructure/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def build_index(df: pd.DataFrame) -> pd.MultiIndex:
"""
if df.loc[:, EXCHANGE_KEYS].isna().any().all():
df = fill_df_keys_with_fields(df)
assert df.loc[:, EXCHANGE_KEYS].notna().all().all(), "Cannot find all keys."
_df = df.loc[:, EXCHANGE_KEYS].notna()
assert _df.all().all(), "Cannot find all keys. {} of {} exchanges are broken.".format(len(df[_df]),
len(df))
unknown_flows = df.loc[:, "flow type"].isna()
if unknown_flows.any():
print("Not all flow types are known, guessing {} flows".format(
Expand Down
2 changes: 1 addition & 1 deletion activity_browser/ui/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .cutoff_menu import CutoffMenu
from .database_copy import CopyDatabaseDialog
from .dialog import (
ForceInputDialog, TupleNameDialog, ExcelReadDialog, ChoiceSelectionDialog,
ForceInputDialog, TupleNameDialog, ExcelReadDialog,
DatabaseLinkingDialog, DefaultBiosphereDialog
)
from .line_edit import (SignalledPlainTextEdit, SignalledComboEdit,
Expand Down
49 changes: 0 additions & 49 deletions activity_browser/ui/widgets/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,55 +54,6 @@ def get_text(cls, parent: QtWidgets.QWidget, title: str, label: str, text: str =
return obj


class ChoiceSelectionDialog(QtWidgets.QDialog):
"""Given a number of options, select one of them."""
def __init__(self, parent=None):
super().__init__(parent)

self.input_box = QtWidgets.QGroupBox(self)
self.input_box.setStyleSheet(style_group_box.border_title)
input_field_layout = QtWidgets.QVBoxLayout()
self.input_box.setLayout(input_field_layout)
self.group = QtWidgets.QButtonGroup(self)
self.group.setExclusive(True)

self.buttons = QtWidgets.QDialogButtonBox(
QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel,
)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)

layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.input_box)
layout.addWidget(self.buttons)
self.setLayout(layout)

@property
def choice(self) -> str:
"""Returns the name of the chosen option, allowing for a comparison"""
checked = self.group.checkedButton()
return checked.text()

@classmethod
def get_choice(cls, parent: QtWidgets.QWidget, *choices) -> 'ChoiceSelectionDialog':
assert len(choices) > 0, "Must give choices to choose from."

obj = cls(parent)
obj.setWindowTitle("Select the option")

iterable = iter(choices)
first = QtWidgets.QRadioButton(str(next(iterable)))
first.setChecked(True)
obj.group.addButton(first)
obj.input_box.layout().addWidget(first)
for choice in iterable:
btn = QtWidgets.QRadioButton(str(choice))
obj.group.addButton(btn)
obj.input_box.layout().addWidget(btn)
obj.input_box.updateGeometry()
return obj


class TupleNameDialog(QtWidgets.QDialog):
def __init__(self, parent=None):
super().__init__(parent)
Expand Down