Skip to content

Commit

Permalink
TST: add regression tests for issue 13176
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Feb 13, 2024
1 parent c82a9c4 commit d7d5540
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions astropy/table/tests/test_index.py
Expand Up @@ -616,3 +616,68 @@ def test_hstack_qtable_table():
def test_index_slice_exception():
with pytest.raises(TypeError, match="index_slice must be tuple or slice"):
SlicedIndex(None, None)


@pytest.mark.parametrize(
"col_a_constructor, expected_row_repr_lines, expected_table_pformat",
[
pytest.param(
lambda vals: vals,
[
"<Row index=0>",
" c b a ",
"int64 int64 int64",
"----- ----- -----",
" 0 1 3",
],
[
" c b a ",
"--- --- ---",
" 2 2 2",
" 3 2 2",
],
id="list",
),
pytest.param(
lambda vals: Time(vals, format="cxcsec"),
[
"<Row index=0>",
" c b a ",
"int64 int64 Time",
"----- ----- ----",
" 0 1 3.0",
],
[
" c b a ",
"--- --- ---",
" 2 2 2.0",
" 3 2 2.0",
],
id="Time",
),
pytest.param(
lambda vals: u.Quantity(vals, unit="m"),
"...",
"...",
id="Quantity",
),
],
)
def test_multi_index(
col_a_constructor, expected_row_repr_lines, expected_table_pformat
):
# see https://github.com/astropy/astropy/issues/13176
vals_a = [3, 3, 2, 2, 1]
vals_b = [1, 2, 2, 2, 1]
vals_c = [0, 1, 2, 3, 4]

col_a = col_a_constructor(vals_a)
t = QTable([vals_c, vals_b, col_a], names=("c", "b", "a"))
t.add_index(["a", "b"])
res1 = t.loc[t["a"][0], t["b"][0]]
assert isinstance(res1, Row)
assert repr(res1).splitlines() == expected_row_repr_lines

res2 = t.loc[t["a"][2], t["b"][2]]
assert isinstance(res2, Table)
assert res2.pformat() == expected_table_pformat

0 comments on commit d7d5540

Please sign in to comment.