Skip to content

Commit

Permalink
release v1.3 with non-experimental sequences (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderland authored Oct 3, 2019
1 parent 54ac478 commit b258896
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 100 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ Changes are grouped as follows
- Separate read/write fields on data classes

## [Unreleased]

## [1.3.0] - 2019-10-03
### Changed
- Sequences officially released and no longer considered experimental.
- Sequences data insert no longer takes a default value for columns.

## [1.2.1] - 2019-10-01
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.2.1"
__version__ = "1.3.0"
44 changes: 21 additions & 23 deletions cognite/client/_api/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
from cognite.client import utils
from cognite.client._api_client import APIClient
from cognite.client.data_classes import Sequence, SequenceData, SequenceFilter, SequenceList, SequenceUpdate
from cognite.client.utils._experimental_warning import experimental_api


@experimental_api(api_name="Sequences")
class SequencesAPI(APIClient):
_RESOURCE_PATH = "/sequences"
_LIST_CLASS = SequenceList
Expand Down Expand Up @@ -82,13 +80,13 @@ def retrieve(self, id: Optional[int] = None, external_id: Optional[str] = None)
Get sequences by id::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.sequences.retrieve(id=1)
Get sequences by external id::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.sequences.retrieve(external_id="1")
"""
Expand All @@ -111,13 +109,13 @@ def retrieve_multiple(
Get sequences by id::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.sequences.retrieve_multiple(ids=[1, 2, 3])
Get sequences by external id::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.sequences.retrieve_multiple(external_ids=["abc", "def"])
"""
Expand Down Expand Up @@ -158,20 +156,20 @@ def list(
List sequences::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.sequences.list(limit=5)
Iterate over sequences::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> for seq in c.sequences:
... seq # do something with the sequences
Iterate over chunks of sequences to reduce memory load::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> for seq_list in c.sequences(chunk_size=2500):
... seq_list # do something with the sequences
Expand Down Expand Up @@ -205,7 +203,7 @@ def create(self, sequence: Union[Sequence, List[Sequence]]) -> Union[Sequence, S
Create a new sequence::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import Sequence
>>> c = CogniteClient()
>>> column_def = [{"valueType":"STRING","externalId":"user","description":"some description"}, {"valueType":"DOUBLE","externalId":"amount"}]
Expand Down Expand Up @@ -250,7 +248,7 @@ def delete(self, id: Union[int, List[int]] = None, external_id: Union[str, List[
Delete sequences by id or external id::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.sequences.delete(id=[1,2,3], external_id="3")
"""
Expand All @@ -271,15 +269,15 @@ def update(
Update a sequence that you have fetched. This will perform a full update of the sequences::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.sequences.retrieve(id=1)
>>> res.description = "New description"
>>> res = c.sequences.update(res)
Perform a partial update on a sequence, updating the description and adding a new field to metadata::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import SequenceUpdate
>>> c = CogniteClient()
>>> my_update = SequenceUpdate(id=1).description.set("New description").metadata.add({"key": "value"})
Expand Down Expand Up @@ -312,7 +310,7 @@ def search(
Search for a sequence::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.sequences.search(name="some name")
"""
Expand Down Expand Up @@ -357,29 +355,29 @@ def insert(
Examples:
Your rows of data can be a list of tuples where the first element is the rownumber and the second element is the data to be inserted::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> seq = c.sequences.create(Sequence(columns=[{"valueType": "STRING", "externalId":"col_a"},{"valueType": "DOUBLE", "externalId":"col_b"}]))
>>> data = [(1, ['pi',3.14]), (2, ['e',2.72]) ]
>>> c.sequences.data.insert(column_external_ids=["col_a","col_b"], rows=data, id=1)
They can also be provided as a list of API-style objects with a rowNumber and values field::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> data = [{"rowNumber": 123, "values": ['str',3]}, {"rowNUmber": 456, "values": ["bar",42]} ]
>>> c.sequences.data.insert(data, id=1, column_external_ids=["col_a","col_b"]) # implicit columns are retrieved from metadata
Or they can be a given as a dictionary with row number as the key, and the value is the data to be inserted at that row::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> data = {123 : ['str',3], 456 : ['bar',42] }
>>> c.sequences.data.insert(column_external_ids=['stringColumn','intColumn'], rows=data, id=1)
Finally, they can be a SequenceData object retrieved from another request. In this case column_external_ids from this object are used as well.
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> data = c.sequences.data.retrieve(id=2,start=0,end=10)
>>> c.sequences.data.insert(rows=data, id=1,column_external_ids=None)
Expand Down Expand Up @@ -429,7 +427,7 @@ def insert_dataframe(
Examples:
Multiply data in the sequence by 2::
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> df = c.sequences.data.retrieve_dataframe(id=123, start=0, end=None)
>>> c.sequences.data.insert_dataframe(df*2, id=123, external_id_headers=True)
Expand All @@ -455,7 +453,7 @@ def delete(self, rows: List[int], id: int = None, external_id: str = None) -> No
Examples:
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.sequences.data.delete(id=0, rows=[1,2,42])
"""
Expand All @@ -480,7 +478,7 @@ def delete_range(self, start: int, end: Union[int, None], id: int = None, extern
Examples:
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.sequences.data.delete_range(id=0, start=0, end=None)
"""
Expand Down Expand Up @@ -518,7 +516,7 @@ def retrieve(
Examples:
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.sequences.data.retrieve(id=0, start=0, end=None)
>>> tuples = [(r,v) for r,v in res.items()] # You can use this iterator in for loops and list comprehensions,
Expand Down Expand Up @@ -561,7 +559,7 @@ def retrieve_dataframe(
Examples:
>>> from cognite.client.experimental import CogniteClient
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> df = c.sequences.data.retrieve_dataframe(id=0, start=0, end=None)
"""
Expand Down
2 changes: 2 additions & 0 deletions cognite/client/_cognite_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from cognite.client._api.iam import IAMAPI
from cognite.client._api.login import LoginAPI
from cognite.client._api.raw import RawAPI
from cognite.client._api.sequences import SequencesAPI
from cognite.client._api.three_d import ThreeDAPI
from cognite.client._api.time_series import TimeSeriesAPI
from cognite.client._api_client import APIClient
Expand Down Expand Up @@ -68,6 +69,7 @@ def __init__(
self.events = EventsAPI(self._config, api_version=self._API_VERSION, cognite_client=self)
self.files = FilesAPI(self._config, api_version=self._API_VERSION, cognite_client=self)
self.iam = IAMAPI(self._config, api_version=self._API_VERSION, cognite_client=self)
self.sequences = SequencesAPI(self._config, api_version=self._API_VERSION, cognite_client=self)
self.time_series = TimeSeriesAPI(self._config, api_version=self._API_VERSION, cognite_client=self)
self.raw = RawAPI(self._config, api_version=self._API_VERSION, cognite_client=self)
self.three_d = ThreeDAPI(self._config, api_version=self._API_VERSION, cognite_client=self)
Expand Down
2 changes: 0 additions & 2 deletions cognite/client/experimental.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from cognite.client._api.model_hosting import ModelHostingAPI
from cognite.client._api.relationships import RelationshipsAPI
from cognite.client._api.sequences import SequencesAPI
from cognite.client._cognite_client import CogniteClient as Client


class CogniteClient(Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.sequences = SequencesAPI(self._config, api_version=self._API_VERSION, cognite_client=self)
self.model_hosting = ModelHostingAPI(self._config, api_version="0.6", cognite_client=self)
self.relationships = RelationshipsAPI(self._config, api_version="playground", cognite_client=self)
3 changes: 3 additions & 0 deletions cognite/client/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from cognite.client._api.iam import IAMAPI, APIKeysAPI, GroupsAPI, SecurityCategoriesAPI, ServiceAccountsAPI
from cognite.client._api.login import LoginAPI
from cognite.client._api.raw import RawAPI, RawDatabasesAPI, RawRowsAPI, RawTablesAPI
from cognite.client._api.sequences import SequencesAPI, SequencesDataAPI
from cognite.client._api.three_d import (
ThreeDAPI,
ThreeDAssetMappingAPI,
Expand Down Expand Up @@ -50,6 +51,8 @@ def __init__(self, *args, **kwargs):
self.raw.databases = MagicMock(spec_set=RawDatabasesAPI)
self.raw.tables = MagicMock(spec_set=RawTablesAPI)
self.raw.rows = MagicMock(spec_set=RawRowsAPI)
self.sequences = MagicMock(spec=SequencesAPI)
self.sequences.data = MagicMock(spec_set=SequencesDataAPI)


@contextmanager
Expand Down
125 changes: 60 additions & 65 deletions docs/source/cognite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,66 @@ Data classes
:members:
:show-inheritance:

Sequences
---------

Retrieve a sequence by id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.retrieve

Retrieve multiple sequences by id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.retrieve_multiple

List sequences
^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.list

Search for sequences
^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.search

Create a sequence
^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.create

Delete sequences
^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.delete

Update sequences
^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.update

Retrieve data
^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.retrieve

Retrieve pandas dataframe
^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.retrieve_dataframe

Insert rows into a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.insert

Insert a pandas dataframe into a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.insert_dataframe

Delete rows from a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.delete

Delete a range of rows from a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.delete_range

Data classes
^^^^^^^^^^^^
.. automodule:: cognite.client.data_classes.sequences
:members:
:show-inheritance:

Raw
---
Expand Down Expand Up @@ -971,71 +1031,6 @@ Data classes
:members:
:show-inheritance:


Sequences
---------
.. WARNING::
The sequences API is experimental and subject to breaking changes. It should not be used in production code.

Retrieve a sequence by id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.retrieve

Retrieve multiple sequences by id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.retrieve_multiple

List sequences
^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.list

Search for sequences
^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.search

Create a sequence
^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.create

Delete sequences
^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.delete

Update sequences
^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesAPI.update

Retrieve data
^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.retrieve

Retrieve pandas dataframe
^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.retrieve_dataframe

Insert rows into a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.insert

Insert a pandas dataframe into a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.insert_dataframe

Delete rows from a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.delete

Delete a range of rows from a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.sequences.SequencesDataAPI.delete_range

Data classes
^^^^^^^^^^^^
.. automodule:: cognite.client.data_classes.sequences
:members:
:show-inheritance:


Relationships
-------------
.. WARNING::
Expand Down
Loading

0 comments on commit b258896

Please sign in to comment.