8000 Add a prototype of the dataframe interchange protocol by rgommers · Pull Request #38 · data-apis/dataframe-api · GitHub
[go: up one dir, main page]

Skip to content

Add a prototype of the dataframe interchange protocol #38

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 13 commits into from
Jun 25, 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
Minor change: add a test for strided columns
  • Loading branch information
rgommers committed Apr 7, 2021
commit 90b4f42630d058a5637f38d498a58c147299192c
17 changes: 16 additions & 1 deletion protocol/pandas_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import pandas as pd
import numpy as np
import pandas._testing as tm
import pytest


# A typing protocol could be added later to let Mypy validate code using
Expand Down Expand Up @@ -137,7 +138,10 @@ def __init__(self, x : np.ndarray) -> None:
Handle only regular columns (= numpy arrays) for now.
"""
if not x.strides == (x.dtype.itemsize,):
# Array is not contiguous - is this possible?
# Array is not contiguous - this is possible to get in Pandas,
# there was some discussion on whether to support it. Som extra
# complexity for libraries that don't support it (e.g. Arrow),
# but would help with numpy-based libraries like Pandas.
raise RuntimeError("Design needs fixing - non-contiguous buffer")

# Store the numpy array in which the data resides as a private
Expand Down Expand Up @@ -444,7 +448,18 @@ def test_mixed_intfloat():
tm.assert_frame_equal(df, df2)


def test_noncontiguous_columns():
# Currently raises: TBD whether it should work or not, see code comment
# where the RuntimeError is raised.
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
df = pd.DataFrame(arr)
assert df[0].to_numpy().strides == (24,)
pytest.raises(RuntimeError, from_dataframe, df)
#df2 = from_dataframe(df)


if __name__ == '__main__':
test_float_only()
test_mixed_intfloat()
test_noncontiguous_columns()

0