feat: Add Polars DataFrame support
Pull Request description
feat: Add Polars DataFrame support
- Create DataFrame abstraction layer for pandas/polars compatibility
- Update plotting backends to handle both DataFrame types
- Add polars dependency and documentation
- Maintain existing API and functionality
Which issue this PR aims to resolve or fix?
Solve #55
How to test these changes
- Ensure you have both pandas and polars installed
- Run existing tests to ensure compatibility with both DataFrame types
- Verify that plotting functions work with both pandas and polars DataFrames
Pull Request checklists
This PR is a:
- [ ] bug-fix
- [x] new feature
- [ ] maintenance
About this PR:
- [x] it includes tests.
- [ ] the tests are executed on CI.
- [ ] the tests generate log file(s) (path).
- [x] pre-commit hooks were executed locally.
- [ ] this PR requires a project documentation update.
Author's checklist:
- [x] I have reviewed the changes and it contains no misspelling.
- [x] The code is well commented, especially in the parts that contain more complexity.
- [x] New and old tests passed locally.
Additional information
Reviewer's checklist
Copy and paste this template for your review's note:
## Reviewer's Checklist
- [ ] I managed to reproduce the problem locally from the `main` branch
- [ ] I managed to test the new changes locally
- [ ] I confirm that the issues mentioned were fixed/resolved.
Summary by CodeRabbit
-
New Features
- Expanded support for both pandas and polars DataFrames, offering greater flexibility for data visualization.
- Enhanced interactive plotting with intuitive zoom, pan, and hover functionalities, plus improved customizable styling and annotations.
-
Documentation
- Introduced a new "Quick Start" guide featuring example code to streamline the onboarding process for new users.
Walkthrough
This pull request enhances the pyOpenMS-Viz library by adding support for both pandas and polars DataFrames. The documentation is updated with a new "Quick Start" section and example code, while a new plot function is introduced to accept either DataFrame type. Internal modifications improve data handling by refactoring column accesses through dedicated methods and wrapping DataFrames using a unified interface. Additionally, the changes update type hints and imports in various visualization backends and add a new dependency on the polars library.
Changes
| File(s) | Change Summary |
|---|---|
| README.md | - Added a new "Quick Start" section with code examples showcasing pandas and polars usage. - Updated documentation to highlight interactive plot features and customizable styling. |
| pyopenms_viz/init.py | - Introduced a new plot function supporting both pandas and polars DataFrames. - Enhanced the function with detailed docstrings and flexible argument handling through PlotAccessor. |
| pyopenms_viz/_bokeh/core.py, pyopenms_viz/_matplotlib/core.py, pyopenms_viz/_plotly/core.py | - Updated import statements to include extended type hints and new libraries (e.g., numpy, DataFrameWrapper). - In Bokeh, data is now converted with .to_pandas() for ColumnDataSource compatibility; Matplotlib’s groupby call has been adjusted. |
| pyopenms_viz/_core.py | - Modified the BasePlot class to accept a union of DataFrame types using wrap_dataframe. - Replaced direct column access with get_column and set_column methods. - Added new imports for enhanced visualization handling. |
| pyopenms_viz/_dataframe.py | - Added a new file providing the DataFrameWrapper and GroupByWrapper classes, along with the wrap_dataframe function, offering a unified interface for both pandas and polars DataFrames. |
| requirements.txt | - Added a dependency: polars>=0.20.7. |
Sequence Diagram(s)
sequenceDiagram
participant U as User
participant P as pyopenms_viz.plot
participant DF as DataFrameWrapper
participant PA as PlotAccessor
U->>P: Call plot(data, *args, **kwargs)
P->>DF: wrap_dataframe(data)
DF-->>P: Return wrapped DataFrame
P->>PA: Initialize PlotAccessor with wrapped data and parameters
PA-->>P: Provide plotting interface
P-->>U: Return interactive plot
Possibly related issues
- OpenMS/pyopenms_viz#55: The PR introduces support for polars DataFrames in the plot function, addressing the need for a unified interface as described in the issue.
Poem
I'm a rabbit, hopping with glee,
New plots and wrappers set my code free.
Pandas and polars now side by side,
Quick Start carrots guide the ride.
In fields of data, I dance and play—
Celebrating changes in a joyful way!
🐇✨
[!TIP]
⚡🧪 Multi-step agentic review comment chat (experimental)
- We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments. - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.