|
26 | 26 | import pandas as pd
|
27 | 27 | import numpy as np
|
28 | 28 | import pandas._testing as tm
|
| 29 | +import pytest |
29 | 30 |
|
30 | 31 |
|
31 | 32 | # A typing protocol could be added later to let Mypy validate code using
|
@@ -137,7 +138,10 @@ def __init__(self, x : np.ndarray) -> None:
|
137 | 138 | Handle only regular columns (= numpy arrays) for now.
|
138 | 139 | """
|
139 | 140 | 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. |
141 | 145 | raise RuntimeError("Design needs fixing - non-contiguous buffer")
|
142 | 146 |
|
143 | 147 | # Store the numpy array in which the data resides as a private
|
@@ -444,7 +448,18 @@ def test_mixed_intfloat():
|
444 | 448 | tm.assert_frame_equal(df, df2)
|
445 | 449 |
|
446 | 450 |
|
| 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 | + |
447 | 461 | if __name__ == '__main__':
|
448 | 462 | test_float_only()
|
449 | 463 | test_mixed_intfloat()
|
| 464 | + test_noncontiguous_columns() |
450 | 465 |
|
0 commit comments