-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DesignMatrixPanel to show DataFrame parameters in a table
- Button to show the parameters is shown when design_matrix is present - Add test for design matrix show parameters button
- Loading branch information
Showing
4 changed files
with
143 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Optional | ||
|
||
import pandas as pd | ||
from qtpy.QtGui import QStandardItem, QStandardItemModel | ||
from qtpy.QtWidgets import QDialog, QTableView, QVBoxLayout, QWidget | ||
|
||
|
||
class DesignMatrixPanel(QDialog): | ||
def __init__( | ||
self, | ||
design_matrix_df: pd.DataFrame, | ||
filename: str, | ||
parent: Optional[QWidget] = None, | ||
) -> None: | ||
super().__init__(parent) | ||
|
||
self.setWindowTitle(f"Design matrix parameters from {filename}") | ||
|
||
table_view = QTableView(self) | ||
table_view.setEditTriggers(QTableView.NoEditTriggers) | ||
|
||
self.model = self.create_model(design_matrix_df) | ||
table_view.setModel(self.model) | ||
|
||
table_view.resizeColumnsToContents() | ||
table_view.resizeRowsToContents() | ||
|
||
layout = QVBoxLayout() | ||
layout.addWidget(table_view) | ||
self.setLayout(layout) | ||
self.adjustSize() | ||
|
||
@staticmethod | ||
def create_model(design_matrix_df: pd.DataFrame) -> QStandardItemModel: | ||
model = QStandardItemModel() | ||
|
||
if isinstance(design_matrix_df.columns, pd.MultiIndex): | ||
header_labels = [str(col[-1]) for col in design_matrix_df.columns] | ||
else: | ||
header_labels = design_matrix_df.columns.astype(str).tolist() | ||
|
||
model.setHorizontalHeaderLabels(header_labels) | ||
|
||
for index, _ in design_matrix_df.iterrows(): | ||
items = [ | ||
QStandardItem(str(design_matrix_df.at[index, col])) | ||
for col in design_matrix_df.columns | ||
] | ||
model.appendRow(items) | ||
return model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters