Skip to content

Commit

Permalink
sequences pandas fix and release 1.1.12 (#557)
Browse files Browse the repository at this point in the history
* sequences pandas fix
* release 1.1.12
  • Loading branch information
sanderland authored Oct 1, 2019
1 parent 380bc0e commit d61e72a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ Changes are grouped as follows

## [Unreleased]

## [1.1.12] - 2019-10-01
### Fixed
- Fixed a bug in time series pagination where getting 100k datapoints could cause a missing id error when using include_outside_points.
- SequencesData `to_pandas` no longer returns NaN on integer zero columns.
- Fixed a bug where the JSON encoder would throw circular reference errors on unknown data types, including numpy floats.

## [1.1.11] - 2019-09-23
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from cognite.client._cognite_client import CogniteClient

__version__ = "1.1.11"
__version__ = "1.1.12"
4 changes: 3 additions & 1 deletion cognite/client/data_classes/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ def to_pandas(self) -> "pandas.DataFrame":
pd = utils._auxiliary.local_import("pandas")

return pd.DataFrame(
[[x or math.nan for x in r] for r in self.values], index=self.row_numbers, columns=self.column_external_ids
[[x if x is not None else math.nan for x in r] for r in self.values],
index=self.row_numbers,
columns=self.column_external_ids,
)

@property
Expand Down
23 changes: 23 additions & 0 deletions tests/tests_unit/test_api/test_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ def mock_get_sequence_data_two_col(rsps):
yield rsps


@pytest.fixture
def mock_get_sequence_data_two_col_with_zero(rsps):
json = {
"id": 0,
"externalId": "eid",
"columns": [{"externalId": "str"}, {"externalId": "lon"}],
"rows": [{"rowNumber": 12, "values": ["string-12", 0]}],
}
rsps.add(rsps.POST, SEQ_API._get_base_url_with_base_path() + "/sequences/data/list", status=200, json=json)
yield rsps


@pytest.fixture
def mock_get_sequence_data_with_null(rsps):
json = {
Expand Down Expand Up @@ -421,6 +433,17 @@ def test_retrieve_dataframe_columns_mixed(self, mock_seq_response, mock_get_sequ
assert isinstance(data, SequenceData)
assert ["col1", "col2"] == list(data.to_pandas().columns)

def test_retrieve_dataframe_columns_mixed_with_zero(
self, mock_seq_response, mock_get_sequence_data_two_col_with_zero
):
import pandas as pd

data = SEQ_API.data.retrieve(external_id="foo", start=0, end=100)
assert isinstance(data, SequenceData)
df = data.to_pandas()
expected_df = pd.DataFrame(index=[12], data=[["string-12", 0]], columns=["str", "lon"])
pd.testing.assert_frame_equal(expected_df, df)

def test_retrieve_dataframe_columns_many_extid(self, mock_get_sequence_data_many_columns):
data = SEQ_API.data.retrieve(external_id="foo", start=1000000, end=1100000)
assert isinstance(data, SequenceData)
Expand Down

0 comments on commit d61e72a

Please sign in to comment.