Skip to content

Commit 66b5a24

Browse files
committed
Add column filter tests
1 parent ff2cb53 commit 66b5a24

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/test_stancsv.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def test_parsing_adaptation_lines():
181181
b"# Step size = 0.787025\n",
182182
b"# Diagonal elements of inverse mass matrix:\n",
183183
b"# 1\n",
184+
b"# Elapsed Time\n",
184185
]
185186
step_size, mass_matrix = stancsv.parse_hmc_adaptation_lines(lines)
186187
assert step_size == 0.787025
@@ -359,3 +360,32 @@ def test_extract_header_line():
359360
assert stancsv.extract_header_line([b""])
360361
with pytest.raises(ValueError):
361362
assert stancsv.extract_header_line([b"1,2\n"])
363+
364+
365+
def test_column_filter_basic():
366+
data = [b"1,2,3\n", b"4,5,6\n"]
367+
indexes = [0, 2]
368+
expected = [b"1,3\n", b"4,6\n"]
369+
assert stancsv.filter_csv_bytes_by_columns(data, indexes) == expected
370+
371+
372+
def test_column_filter_empty_input():
373+
assert not stancsv.filter_csv_bytes_by_columns([], [0])
374+
375+
376+
def test_column_filter_empty_indexes():
377+
data = [b"1,2,3\n", b"4,5,6\n"]
378+
assert stancsv.filter_csv_bytes_by_columns(data, []) == [b"\n", b"\n"]
379+
380+
381+
def test_column_filter_single_column():
382+
data = [b"a,b,c\n", b"d,e,f\n"]
383+
assert stancsv.filter_csv_bytes_by_columns(data, [1]) == [b"b\n", b"e\n"]
384+
385+
386+
def test_column_filter_non_consecutive_indexes():
387+
data = [b"9,8,7,6\n", b"5,4,3,2\n"]
388+
assert stancsv.filter_csv_bytes_by_columns(data, [2, 0]) == [
389+
b"7,9\n",
390+
b"3,5\n",
391+
]

0 commit comments

Comments
 (0)