-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ingest different df types + tests #134
Merged
vincentarelbundock
merged 5 commits into
vincentarelbundock:main
from
artiom-matvei:fix_issue_108_ingest_narwhals
Oct 27, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb4d158
ingest different df types + tests
artiom-matvei 65f9d19
removed joint_hypotheses option for obj being of type dataframe
artiom-matvei f8840a7
updated pyproject.toml to reduce dependencies duckdv, pyarrow, scipy
artiom-matvei 0eb894b
comparisons documentation homogenization
artiom-matvei a04d140
removed unused test data file
artiom-matvei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pytest | ||
import pandas as pd | ||
import polars as pl | ||
import duckdb | ||
import pyarrow as pa | ||
import narwhals as nw | ||
from marginaleffects.utils import ingest | ||
from typing import Callable | ||
|
||
|
||
def get_sample_data(): | ||
return pd.DataFrame( | ||
{ | ||
"id": [1, 2, 3], | ||
"name": ["Alice", "Bob", "Charlie"], | ||
"age": [25, 30, 35], | ||
"score": [85.5, 90.0, 95.5], | ||
} | ||
) | ||
|
||
|
||
sample_data = get_sample_data() | ||
|
||
|
||
@pytest.fixture | ||
def sample_pandas_df(): | ||
return get_sample_data() | ||
|
||
|
||
@pytest.fixture | ||
def sample_polars_df(): | ||
pd_df = get_sample_data() | ||
return pl.from_pandas(pd_df) | ||
|
||
|
||
@pytest.fixture | ||
def sample_duckdb_df(): | ||
# Using DuckDB to create a DataFrame | ||
con = duckdb.connect() | ||
return con.execute("SELECT * FROM sample_data").df() | ||
|
||
|
||
def test_ingest_pandas(sample_pandas_df): | ||
result = ingest(sample_pandas_df) | ||
assert isinstance(result, pl.DataFrame), "Result should be a Polars DataFrame" | ||
# Verify contents | ||
expected = pl.from_pandas(sample_pandas_df) | ||
assert result.equals( | ||
expected | ||
), "Ingested DataFrame does not match expected Polars DataFrame" | ||
|
||
|
||
def test_ingest_polars(sample_polars_df): | ||
result = ingest(sample_polars_df) | ||
assert isinstance(result, pl.DataFrame), "Result should be a Polars DataFrame" | ||
# Verify contents | ||
expected = sample_polars_df | ||
assert result.equals( | ||
expected | ||
), "Ingested DataFrame does not match expected Polars DataFrame" | ||
|
||
|
||
def test_ingest_duckdb(sample_duckdb_df): | ||
result = ingest(sample_duckdb_df) | ||
assert isinstance(result, pl.DataFrame), "Result should be a Polars DataFrame" | ||
# Verify contents | ||
expected = pl.from_pandas(sample_duckdb_df) | ||
assert result.equals( | ||
expected | ||
), "Ingested DataFrame does not match expected Polars DataFrame" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like
obj
is of typemodel
and it shouldn't ever be of typedataframe
. It was introduced here #94 but not sure why. I also checked in R andobj
is not adataframe
in R either.If it were to be a dataframe all the following operations would fail so I think we can remove it. @vincentarelbundock do you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems right but I won't have time to dig deep, so I'll trust you here.