|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 |
|
| 6 | +from cognite.client import CogniteClient |
6 | 7 | from cognite.client._api.raw import RawRowsAPI |
7 | 8 | from cognite.client.data_classes import Database, DatabaseList, Row, RowList, RowWrite, RowWriteList, Table, TableList |
8 | 9 | from cognite.client.exceptions import CogniteAPIError |
9 | | -from tests.utils import jsgz_load |
| 10 | +from tests.utils import assert_all_value_types_equal, jsgz_load |
10 | 11 |
|
11 | 12 |
|
12 | 13 | @pytest.fixture |
@@ -81,6 +82,29 @@ def mock_retrieve_raw_rows_response_two_rows(rsps, cognite_client): |
81 | 82 | yield rsps |
82 | 83 |
|
83 | 84 |
|
| 85 | +@pytest.fixture |
| 86 | +def integer_rows_response() -> dict: |
| 87 | + return { |
| 88 | + "items": [ |
| 89 | + {"key": "row1", "columns": {"c1": 1, "c2": 4.0}, "lastUpdatedTime": 0}, |
| 90 | + {"key": "row2", "columns": {"c1": 2, "c2": 3}, "lastUpdatedTime": 1}, |
| 91 | + {"key": "row3", "columns": {"c1": 3, "c2": 1}, "lastUpdatedTime": 2}, |
| 92 | + {"key": "row4", "columns": {"c1": None, "c2": 0.1}, "lastUpdatedTime": 3}, |
| 93 | + ] |
| 94 | + } |
| 95 | + |
| 96 | + |
| 97 | +@pytest.fixture |
| 98 | +def mock_retrieve_integer_rows(rsps, integer_rows_response: dict, cognite_client: CogniteClient): |
| 99 | + rsps.add( |
| 100 | + rsps.GET, |
| 101 | + cognite_client.raw._get_base_url_with_base_path() + "/raw/dbs/db1/tables/table1/rows", |
| 102 | + status=200, |
| 103 | + json=integer_rows_response, |
| 104 | + ) |
| 105 | + yield rsps |
| 106 | + |
| 107 | + |
84 | 108 | @pytest.fixture |
85 | 109 | def mock_retrieve_raw_rows_response_one_row(rsps, cognite_client): |
86 | 110 | response_body = {"items": [{"key": "row1", "columns": {"c1": 1, "c2": "2"}, "lastUpdatedTime": 0}]} |
@@ -378,6 +402,19 @@ def test_retrieve_dataframe_two_rows(self, cognite_client, mock_retrieve_raw_row |
378 | 402 | pd.Timestamp(1, unit="ms"), |
379 | 403 | ] |
380 | 404 |
|
| 405 | + def test_retrieve_dataframe_integers( |
| 406 | + self, |
| 407 | + cognite_client: CogniteClient, |
| 408 | + mock_retrieve_integer_rows, |
| 409 | + integer_rows_response: dict, |
| 410 | + ) -> None: |
| 411 | + result = cognite_client.raw.rows.retrieve_dataframe(db_name="db1", table_name="table1", infer_dtypes=False) |
| 412 | + |
| 413 | + actual = result.to_dict(orient="index") |
| 414 | + expected = {row["key"]: row["columns"] for row in integer_rows_response["items"]} |
| 415 | + assert_all_value_types_equal(actual, expected) |
| 416 | + assert actual == expected |
| 417 | + |
381 | 418 |
|
382 | 419 | @pytest.mark.parametrize("raw_cls", (Row, RowWrite)) |
383 | 420 | def test_raw_row__direct_column_access(raw_cls): |
|
0 commit comments