-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
from datetime import date | ||
|
||
from cognite.client.data_classes.data_modeling import DirectRelationReference, ViewId | ||
import pytest | ||
|
||
from cognite.client.data_classes.data_modeling import DirectRelationReference, NodeList, ViewId | ||
from cognite.client.data_classes.data_modeling.typed_instances import ( | ||
PropertyOptions, | ||
TypedEdge, | ||
|
@@ -231,6 +233,60 @@ def test_dump_load_person(self) -> None: | |
assert isinstance(loaded.birth_date, date) | ||
assert all(isinstance(sibling, DirectRelationReference) for sibling in loaded.siblings or []) | ||
|
||
@pytest.mark.dsl | ||
def test_to_pandas(self) -> None: | ||
import pandas as pd | ||
|
||
person = PersonRead( | ||
"sp_my_fixed_space", "my_external_id", 1, 0, 0, "John Doe", date(1990, 1, 1), "[email protected]" | ||
) | ||
|
||
df = person.to_pandas() | ||
|
||
pd.testing.assert_series_equal( | ||
df, | ||
pd.Series( | ||
{ | ||
"space": "sp_my_fixed_space", | ||
"external_id": "my_external_id", | ||
"version": 1, | ||
"last_updated_time": pd.Timestamp("1970-01-01 00:00:00"), | ||
"created_time": pd.Timestamp("1970-01-01 00:00:00"), | ||
"instance_type": "node", | ||
"name": "John Doe", | ||
"birth_date": "1990-01-01", | ||
"email": "[email protected]", | ||
} | ||
), | ||
) | ||
|
||
@pytest.mark.dsl | ||
def test_to_pandas_list(self) -> None: | ||
import pandas as pd | ||
|
||
person = NodeList[PersonRead]( | ||
[PersonRead("sp_my_fixed_space", "my_external_id", 1, 0, 0, "John Doe", date(1990, 1, 1), "[email protected]")] | ||
) | ||
|
||
df = person.to_pandas(expand_properties=True) | ||
|
||
pd.testing.assert_frame_equal( | ||
df, | ||
pd.DataFrame( | ||
{ | ||
"space": ["sp_my_fixed_space"], | ||
"external_id": ["my_external_id"], | ||
"version": [1], | ||
"last_updated_time": [pd.Timestamp("1970-01-01 00:00:00")], | ||
"created_time": [pd.Timestamp("1970-01-01 00:00:00")], | ||
"instance_type": ["node"], | ||
"name": ["John Doe"], | ||
"birthDate": ["1990-01-01"], | ||
"email": ["[email protected]"], | ||
} | ||
), | ||
) | ||
|
||
|
||
class TestTypedEdge: | ||
def test_dump_load_flow(self) -> None: | ||
|