Fix for GUI not using pydantic. Also added feature for custom date co…#42
Fix for GUI not using pydantic. Also added feature for custom date co…#42
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors the GUI data source handling to use Pydantic's DataSourceConfig model instead of plain dictionaries, and adds support for custom date column configuration. The changes improve type safety and allow users to specify which column should be treated as the date column in CSV/TSV files.
Changes:
- Updated Signal types to use
DataSourceConfiginstead ofdictfor type-safe data source emission - Added
date_columnfield toDataSourceConfigwith default value 'date' and alias 'date column' - Added UI field in CSV/TSV dialog for users to specify the date column name
- Modified data source instantiation in file dialogs to create
DataSourceConfigobjects
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/midrc_react/gui/pyside6/jsdview.py | Updated Signal type from dict to DataSourceConfig and added import |
| src/midrc_react/gui/pyside6/file_open_dialogs.py | Added date_column UI field, updated file dialogs to create DataSourceConfig instances |
| src/midrc_react/gui/common/jsdview_base.py | Updated Signal type from dict to DataSourceConfig and added import |
| src/midrc_react/core/jsdconfig.py | Added date_column field with alias support to DataSourceConfig |
| src/midrc_react/core/excel_layout.py | Added date column handling logic and return type annotation |
Comments suppressed due to low confidence (1)
src/midrc_react/core/jsdconfig.py:60
- In Pydantic v2,
validate_by_namehas been renamed topopulate_by_name. Since the setup.py specifiespydantic>=2.7.0, you should usepopulate_by_name = Trueinstead to follow Pydantic v2 conventions and avoid using deprecated configuration.
class Config:
validate_by_name = True
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'remove column name text': dialog.remove_column_text_line_edit.text(), | ||
| } | ||
| self.add_data_source.emit(data_source_dict) | ||
| data_source_dict = dialog.get_data() |
There was a problem hiding this comment.
The FileOptionsDialog class does not have a get_data() method, but it's being called here. This will result in an AttributeError at runtime when opening Excel files. You need to either add a get_data() method to FileOptionsDialog that returns the necessary fields (name, description, remove_column_name_text), or directly access the dialog's line edit fields as was done in the previous implementation.
| data_source_dict = dialog.get_data() | |
| if hasattr(dialog, "get_data") and callable(getattr(dialog, "get_data", None)): | |
| data_source_dict = dialog.get_data() | |
| else: | |
| # Fallback: construct the data source dict directly from dialog attributes | |
| data_source_dict = { | |
| "name": getattr(dialog, "name", ""), | |
| "description": getattr(dialog, "description", ""), | |
| "remove_column_name_text": getattr(dialog, "remove_column_name_text", ""), | |
| } |
| if self._date_column not in df.columns: | ||
| self._date_column = df.columns[0] | ||
| df.rename(columns={self._date_column: 'date'}, inplace=True) # Ensure the date column is named 'date' |
There was a problem hiding this comment.
If self._date_column is None (which can happen since it's Optional[str] in DataSourceConfig), this will raise a TypeError when checking None not in df.columns. You should add a check to handle the None case, such as defaulting to 'date' or df.columns[0] before the comparison.
| if self._date_column not in df.columns: | |
| self._date_column = df.columns[0] | |
| df.rename(columns={self._date_column: 'date'}, inplace=True) # Ensure the date column is named 'date' | |
| # Determine which column to use as the date column, handling None and missing cases safely. | |
| if self._date_column is not None and self._date_column in df.columns: | |
| date_column = self._date_column | |
| elif 'date' in df.columns: | |
| # Prefer an existing 'date' column if present. | |
| date_column = 'date' | |
| else: | |
| # Fallback: use the first column in the DataFrame. | |
| date_column = df.columns[0] | |
| # Update the stored date column name to the resolved value. | |
| self._date_column = date_column | |
| df.rename(columns={date_column: 'date'}, inplace=True) # Ensure the date column is named 'date' |
|
|
||
| from midrc_react.gui.pyside6.columnselectordialog import ColumnSelectorDialog, NumericColumnSelectorDialog | ||
|
|
||
| from midrc_react.core.jsdconfig import DataSourceConfig, NumericColumnConfig |
There was a problem hiding this comment.
Import of 'NumericColumnConfig' is not used.
| from midrc_react.core.jsdconfig import DataSourceConfig, NumericColumnConfig | |
| from midrc_react.core.jsdconfig import DataSourceConfig |
…lumn