Skip to content

Commit 90b4f42

Browse files
committed
Minor change: add a test for strided columns
1 parent 35d3c0d commit 90b4f42

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

protocol/pandas_implementation.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import pandas as pd
2727
import numpy as np
2828
import pandas._testing as tm
29+
import pytest
2930

3031

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

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

446450

451+
def test_noncontiguous_columns():
452+
# Currently raises: TBD whether it should work or not, see code comment
453+
# where the RuntimeError is raised.
454+
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
455+
df = pd.DataFrame(arr)
456+
assert df[0].to_numpy().strides == (24,)
457+
pytest.raises(RuntimeError, from_dataframe, df)
458+
#df2 = from_dataframe(df)
459+
460+
447461
if __name__ == '__main__':
448462
test_float_only()
449463
test_mixed_intfloat()
464+
test_noncontiguous_columns()
450465

0 commit comments

Comments
 (0)