diff --git a/CHANGELOG.md b/CHANGELOG.md index 928d55f603..a4d332b97a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [7.62.6] - 2024-09-27 +### Fixed +- Instances with a single property no longer fail `to_pandas()` with `TypeError`, when using expand_properties=True. + ## [7.62.5] - 2024-09-26 ### Added - Add new `client.workflows.triggers.upsert`, this allows upserts of triggers. @@ -26,7 +30,7 @@ Changes are grouped as follows ## [7.62.4] - 2024-09-25 ### Fixed - In the CoreModel, `client.data_classes.data_modeling.cdm` the fields `isUploaded` and `uploadedTime` in - `CogniteFile` are now considered read-only + `CogniteFile` are now considered read-only ## [7.62.3] - 2024-09-24 ### Added @@ -38,7 +42,7 @@ Changes are grouped as follows ## [7.62.1] - 2024-09-23 ### Changed -- Support for `OAuthDeviceCode` now supports non Entra IdPs +- Support for `OAuthDeviceCode` now supports non Entra IdPs ## [7.62.0] - 2024-09-19 ### Added diff --git a/cognite/client/_version.py b/cognite/client/_version.py index 8344819503..d1c2a81b4f 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.62.5" +__version__ = "7.62.6" __api_subversion__ = "20230101" diff --git a/cognite/client/data_classes/data_modeling/instances.py b/cognite/client/data_classes/data_modeling/instances.py index 1642b214c9..1edffcaee8 100644 --- a/cognite/client/data_classes/data_modeling/instances.py +++ b/cognite/client/data_classes/data_modeling/instances.py @@ -472,7 +472,7 @@ def to_pandas( # type: ignore [override] "Can't remove view ID prefix from expanded property rows as source was not unique", RuntimeWarning, ) - return pd.concat((col, prop_df.T.squeeze())).to_frame(name="value") + return pd.concat((col, prop_df.T.squeeze(axis=1))).to_frame(name="value") @abstractmethod def as_apply(self) -> InstanceApply: diff --git a/pyproject.toml b/pyproject.toml index 58821b1b67..4780829978 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.62.5" +version = "7.62.6" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" diff --git a/tests/tests_unit/test_data_classes/test_data_models/test_instances.py b/tests/tests_unit/test_data_classes/test_data_models/test_instances.py index cfdf90b690..3f62f9ce33 100644 --- a/tests/tests_unit/test_data_classes/test_data_models/test_instances.py +++ b/tests/tests_unit/test_data_classes/test_data_models/test_instances.py @@ -481,6 +481,30 @@ def test_expand_properties__list_class_empty_properties( assert "properties" not in expanded_with_empty_properties.columns + def test_node_with_single_property_to_pandas_with_expand_props(self) -> None: + # Bug prior to 7.62.6 made to_pandas(expand_properties=True) fail on nodes with a single property + # due to how squeeze works in pandas, even a DataFrame will be forced into a scalar (to be fair, + # the documentation is very clear on this). + node = Node.load( + { + "space": "DEMO_AppData", + "externalId": "15777214-1234-4321-1234-02f7b4cd349d", + "version": 888, + "lastUpdatedTime": 1694611301244, + "createdTime": 1685430260401, + "instanceType": "node", + "properties": {"DEMO_AppData": {"APM_User/15": {"name": "Foo Bar"}}}, + } + ) + # This has always worked, and should continue to work after the fix + node_df1 = node.to_pandas(expand_properties=False) + assert node_df1.at["properties", "value"] == {"DEMO_AppData": {"APM_User/15": {"name": "Foo Bar"}}} + + # This failed prior to 7.62.6: + node_df2 = node.to_pandas(expand_properties=True) + assert "properties" not in node_df2.index + assert node_df2.at["name", "value"] == "Foo Bar" + class TestTypeInformation: @pytest.mark.dsl