Skip to content

Commit

Permalink
fix type error on inst to pd with single prop and expand True (#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt authored Sep 30, 2024
1 parent 970fedb commit 1adecd9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "7.62.5"
__version__ = "7.62.6"
__api_subversion__ = "20230101"
2 changes: 1 addition & 1 deletion cognite/client/data_classes/data_modeling/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1adecd9

Please sign in to comment.