| 21 | class TestXport: |
| 22 | @pytest.mark.slow |
| 23 | def test1_basic(self, datapath): |
| 24 | # Tests with DEMO_G.xpt (all numeric file) |
| 25 | |
| 26 | # Compare to this |
| 27 | file01 = datapath("io", "sas", "data", "DEMO_G.xpt") |
| 28 | data_csv = pd.read_csv(file01.replace(".xpt", ".csv")) |
| 29 | numeric_as_float(data_csv) |
| 30 | |
| 31 | # Read full file |
| 32 | data = read_sas(file01, format="xport") |
| 33 | tm.assert_frame_equal(data, data_csv) |
| 34 | num_rows = data.shape[0] |
| 35 | |
| 36 | # Test reading beyond end of file |
| 37 | with read_sas(file01, format="xport", iterator=True) as reader: |
| 38 | data = reader.read(num_rows + 100) |
| 39 | assert data.shape[0] == num_rows |
| 40 | |
| 41 | # Test incremental read with `read` method. |
| 42 | with read_sas(file01, format="xport", iterator=True) as reader: |
| 43 | data = reader.read(10) |
| 44 | tm.assert_frame_equal(data, data_csv.iloc[0:10, :]) |
| 45 | |
| 46 | # Test incremental read with `get_chunk` method. |
| 47 | with read_sas(file01, format="xport", chunksize=10) as reader: |
| 48 | data = reader.get_chunk() |
| 49 | tm.assert_frame_equal(data, data_csv.iloc[0:10, :]) |
| 50 | |
| 51 | # Test read in loop |
| 52 | m = 0 |
| 53 | with read_sas(file01, format="xport", chunksize=100) as reader: |
| 54 | for x in reader: |
| 55 | m += x.shape[0] |
| 56 | assert m == num_rows |
| 57 | |
| 58 | # Read full file with `read_sas` method |
| 59 | data = read_sas(file01) |
| 60 | tm.assert_frame_equal(data, data_csv) |
| 61 | |
| 62 | def test1_index(self, datapath): |
| 63 | # Tests with DEMO_G.xpt using index (all numeric file) |