|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +import cudf |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def df_with_index(): |
| 11 | + return cudf.DataFrame( |
| 12 | + {"A": [1, 2, 3], "B": [4, 5, 6]}, index=["x", "y", "z"] |
| 13 | + ) |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def df_without_index(): |
| 18 | + return cudf.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}) |
| 19 | + |
| 20 | + |
| 21 | +def test_dataframe_at_scalar_getitem(df_with_index): |
| 22 | + assert df_with_index.at["x", "A"] == 1 |
| 23 | + assert df_with_index.at["y", "B"] == 5 |
| 24 | + |
| 25 | + |
| 26 | +def test_dataframe_at_scalar_setitem(df_with_index): |
| 27 | + df_with_index.at["x", "A"] = 10 |
| 28 | + assert df_with_index.at["x", "A"] == 10 |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.parametrize("key", [[["x"], "A"], ["x", ["A"]], [["x"], ["A"]]]) |
| 32 | +def test_dataframe_at_rejects_list_like(df_with_index, key): |
| 33 | + with pytest.raises(ValueError, match="Invalid call for scalar access"): |
| 34 | + df_with_index.at[key[0], key[1]] |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.parametrize("key", [[["x"], "A"], ["x", ["A"]]]) |
| 38 | +def test_dataframe_at_setitem_rejects_list_like(df_with_index, key): |
| 39 | + with pytest.raises(ValueError, match="Invalid call for scalar access"): |
| 40 | + df_with_index.at[key[0], key[1]] = 10 |
| 41 | + |
| 42 | + |
| 43 | +def test_dataframe_iat_scalar_getitem(df_without_index): |
| 44 | + assert df_without_index.iat[0, 0] == 1 |
| 45 | + assert df_without_index.iat[1, 1] == 5 |
| 46 | + |
| 47 | + |
| 48 | +def test_dataframe_iat_scalar_setitem(df_without_index): |
| 49 | + df_without_index.iat[0, 0] = 10 |
| 50 | + assert df_without_index.iat[0, 0] == 10 |
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.parametrize("key", [[[0], 0], [0, [0]], [[0], [0]]]) |
| 54 | +def test_dataframe_iat_rejects_list_like(df_without_index, key): |
| 55 | + with pytest.raises( |
| 56 | + ValueError, match="iAt based indexing can only have integer indexers" |
| 57 | + ): |
| 58 | + df_without_index.iat[key[0], key[1]] |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.parametrize("key", [[[0], 0], [0, [0]]]) |
| 62 | +def test_dataframe_iat_setitem_rejects_list_like(df_without_index, key): |
| 63 | + with pytest.raises( |
| 64 | + ValueError, match="iAt based indexing can only have integer indexers" |
| 65 | + ): |
| 66 | + df_without_index.iat[key[0], key[1]] = 10 |
0 commit comments