Add pandas DataFrame support for table rendering in reports#24
Conversation
Co-authored-by: transientlunatic <4365778+transientlunatic@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds optional pandas DataFrame support to Otter reports, completing a TODO item from the README. DataFrames can now be automatically rendered as styled HTML tables using the existing tabulate-based rendering system.
Key Changes:
- Added optional pandas dependency with graceful fallback when unavailable
- Implemented DataFrame-to-HTML conversion using the existing Bootstrap table styling
- Added comprehensive test coverage with conditional pandas availability checks
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| otter/html.py | Adds optional pandas import, dataframe_to_table() function, and registers DataFrame handler when pandas is available |
| pyproject.toml | Defines pandas as an optional dependency under [project.optional-dependencies] |
| tests/test_otter.py | Adds TestPandasSupport test class with two tests that skip gracefully when pandas is unavailable |
| README.rst | Removes TODO, adds usage example demonstrating DataFrame rendering |
| docs/usage.rst | Adds dedicated "Pandas DataFrames" section with usage examples and installation notes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| except ImportError: | ||
| self.pandas_available = False | ||
| self.pd = None | ||
|
|
There was a problem hiding this comment.
The TestPandasSupport class is missing a tearDown method to clean up resources. The test_pandas_dataframe_in_report method creates temporary directories but handles cleanup in a try-finally block within the test itself. For consistency with the existing TestOtterBasics class pattern (lines 24-38), consider adding a tearDown method to handle cleanup uniformly across all tests in this class.
| def tearDown(self): | |
| """Clean up any temporary resources created by tests.""" | |
| # Remove a temporary directory if one was created and stored on the instance | |
| if hasattr(self, "test_dir") and self.test_dir and os.path.isdir(self.test_dir): | |
| shutil.rmtree(self.test_dir) |
There was a problem hiding this comment.
Refactored TestPandasSupport to use setUp/tearDown pattern for consistency with TestOtterBasics. The test_dir and test_file are now created in setUp and cleaned up in tearDown, eliminating the try-finally block. Commit: a97a8ba
transientlunatic
left a comment
There was a problem hiding this comment.
@copilot Please address the comments from code review.
Co-authored-by: transientlunatic <4365778+transientlunatic@users.noreply.github.com>
Summary
Successfully implemented pandas DataFrame support for Otter reports. Refactored test cleanup to follow the same pattern as TestOtterBasics, using setUp/tearDown methods instead of try-finally blocks for better consistency and cleaner code.
Total changes: 5 files changed, 149 insertions(+), 9 deletions(-)
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.