8000 More tests on the API by iskode · Pull Request #49 · data-apis/dataframe-api · GitHub
[go: up one dir, main page]

Skip to content

More tests on the API #49

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

Merged
merged 6 commits into from
Sep 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactors helper function names and signatures
  • Loading branch information
iskode committed Aug 24, 2021
commit 7718c76f465bd83e1a921f66cf484178d47028f3
18 changes: 10 additions & 8 deletions protocol/pandas_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,31 +538,33 @@ def get_chunks(self, n_chunks : Optional[int] = None) -> Iterable['_PandasDataFr
# Roundtrip testing
# -----------------

def test_column(pdcol:pd.Series, col: _PandasColumn):
assert pdcol.size == col.size
def assert_column_equal(col: _PandasColumn, pdcol:pd.Series):
assert col.size == pdcol.size
assert col.offset == 0
assert pdcol.isnull().sum() == col.null_count
assert col.null_count == pdcol.isnull().sum()
assert col.num_chunks() == 1
pytest.raises(RuntimeError, col.get_mask)

def test__dataframe__(df:pd.DataFrame, dfo: DataFrameObject):
def assert_dataframe_equal(dfo: DataFrameObject, df:pd.DataFrame):
assert dfo.num_columns() == len(df.columns)
assert dfo.num_rows() == len(df)
assert dfo.num_chunks() == 1
assert dfo.column_names() == list(df.columns)
for col in df.columns:
test_column(df[col], dfo.get_column_by_name(col))
assert_column_equal(dfo.get_column_by_name(col), df[col])

def test_float_only():
df = pd.DataFrame(data=dict(a=[1.5, 2.5, 3.5], b=[9.2, 10.5, 11.8]))
df2 = from_dataframe(df)
test__dataframe__(df, df.__dataframe__())
assert_dataframe_equal(df.__dataframe__(), df)
tm.assert_frame_equal(df, df2)


def test_mixed_intfloat():
df = pd.DataFrame(data=dict(a=[1, 2, 3], b=[3, 4, 5],
c=[1.5, 2.5, 3.5], d=[9, 10, 11]))
df2 = from_dataframe(df)
test__dataframe__(df, df.__dataframe__())
assert_dataframe_equal(df.__dataframe__(), df)
tm.assert_frame_equal(df, df2)


Expand Down Expand Up @@ -590,7 +592,7 @@ def test_categorical_dtype():
assert col.describe_categorical == (False, True, {0: 1, 1: 2, 2: 5})

df2 = from_dataframe(df)
test__dataframe__(df, df.__dataframe__())
assert_dataframe_equal(df.__dataframe__(), df)
tm.assert_frame_equal(df, df2)


Expand Down
0