Skip to content

New data format support (pandas.DataFrame) #40

Open
mika-long wants to merge 3 commits into
revisit-studies:mainfrom
mika-long:new-data-format-support
Open

New data format support (pandas.DataFrame) #40
mika-long wants to merge 3 commits into
revisit-studies:mainfrom
mika-long:new-data-format-support

Conversation

@mika-long

Copy link
Copy Markdown

Does this PR close any open issues?

Closes #39

Give a longer description of what this PR addresses and why it's needed

  • Extended data() function to accept pandas.DataFrame; helpful for generating components in jupyter notebooks from pandas.DataFrame and not a local csv file.
  • Updated pyproject.toml with requires-python >= 3.10
  • Added a test file (test/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:

  • Update relevant documentation (and specify that any source of data input should be in tidy format)

@JackWilb JackWilb added this to Roadmap Mar 4, 2026
@JackWilb JackWilb moved this to In progress in Roadmap Mar 4, 2026
@JackWilb JackWilb removed this from Roadmap Mar 4, 2026
@JackWilb
JackWilb requested a review from Copilot June 10, 2026 01:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a pandas.DataFrame, with dedicated helpers for each.
  • Add a new test module intended to validate DataFrame support.
  • Set requires-python = ">=3.10" in pyproject.toml and 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
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: support pandas/polars dataframe in addition to CSV

3 participants