New data format support (pandas.DataFrame) #40
Open
mika-long wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for passing a pandas.DataFrame directly into revisitpy.data() so users (especially in notebooks) can build study components without first writing a CSV to disk.
Changes:
- Extend
data()to accept either a CSV file path (str) or apandas.DataFrame, with dedicated helpers for each. - Add a new test module intended to validate DataFrame support.
- Set
requires-python = ">=3.10"inpyproject.tomland update the example notebook to exercise the new behavior.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/test_dataframe_support.py | Adds tests for DataFrame input (currently implemented as top-level script code rather than unittest tests). |
| src/revisitpy/revisitpy.py | Extends data() to accept pandas.DataFrame and adds _data_from_pandas() helper. |
| scripts/test_script.ipynb | Updates the dev notebook with DataFrame support checks and minor import changes. |
| pyproject.toml | Declares Python version requirement (>=3.10). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+6
| import pandas as pd | ||
| import sys | ||
| sys.path.insert(0, '/Users/shenglong/Downloads/revisitpy/src') | ||
|
|
||
| from revisitpy import data | ||
|
|
Comment on lines
+7
to
+28
| # Test 1: CSV file | ||
| print("Test 1: CSV file") | ||
| csv_data = data("tests/config.json") # Replace with actual CSV | ||
| print(f"✓ CSV loaded: {len(csv_data)} rows") | ||
|
|
||
| # Test 2: Pandas DataFrame | ||
| print("\nTest 2: Pandas DataFrame") | ||
| df = pd.DataFrame({ | ||
| 'id': [1, 2, 3], | ||
| 'b1': [0.32, 1.2, 0.6], | ||
| 'b2': [0.01, 1.2, 1.1] | ||
| }) | ||
| df_data = data(df) | ||
| print(f"✓ DataFrame loaded: {len(df_data)} rows") | ||
| print(f" First row: {df_data[0]}") | ||
|
|
||
| # Test 3: Error handling | ||
| print("\nTest 3: Error handling") | ||
| try: | ||
| data(123) # Should fail | ||
| except Exception as e: | ||
| print(f"✓ Correctly raised error: {str(e)[:50]}...") No newline at end of file |
Comment on lines
+569
to
+571
| raise RevisitError( | ||
| message=f"Unsupported data source type: {type(source)}. Use CSV file path (str), pandas DataFrame, or Polars DataFrame" | ||
| ) |
Comment on lines
+554
to
+563
| """ | ||
| Parse data from. various sources into a list of DataRow objects | ||
|
|
||
| Supports: | ||
| - CSV file path (strings) | ||
| - pandas DataFrames | ||
|
|
||
| Args: | ||
| source | ||
| """ |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Does this PR close any open issues?
Closes #39
Give a longer description of what this PR addresses and why it's needed
data()function to acceptpandas.DataFrame; helpful for generating components in jupyter notebooks frompandas.DataFrameand not a localcsvfile.pyproject.tomlwithrequires-python >= 3.10test/test_dataframe_support.py)Provide pictures/videos of the behavior before and after these changes (optional)
Are there any additional TODOs before this PR is ready to go?
TODOs: