Insert

pyclarify.client.Client.insert(data: pyclarify.views.dataframe.DataFrame) pyclarify.views.generics.Response

This call inserts data to one or multiple signals. The signal is given an input id by the user. The signal is uniquely identified by its input ID in combination with the integration ID. If no signal with the given combination exists, an empty signal is created. With the creation of the signal, a unique signal id gets assigned to it. Mirroring the Clarify API call integration.insert .

Parameters

data (DataFrame) – Dataframe containing the values of a signal in a key-value pair, and separate time axis.

Returns

Response.result.data is a dictionary mapping INPUT_ID to SIGNAL_ID.

Return type

Response

See also

Client.data_frame

Retrieve data from selected items.

Client.save_signals

Save meta data for signals.

DataFrame

Model used for transporting data to and from Clarify.

Examples

>>> from pyclarify import Client, DataFrame
>>> client = Client("./clarify-credentials.json")

Inserting some dummy data.

>>> data = DataFrame(
...     series={"INPUT_ID_1": [1, 2], "INPUT_ID_2": [3, 4]},
...     times=["2021-11-01T21:50:06Z",  "2021-11-02T21:50:06Z"]
... )
>>> client.insert(data)

Inserting pandas.DataFrame.

>>> import pandas as pd
>>> df = pd.DataFrame(data={"INPUT_ID_1": [1, 2], "INPUT_ID_2": [3, 4]})
>>> df.index = ["2021-11-01T21:50:06Z",  "2021-11-02T21:50:06Z"]
>>> client.insert(DataFrame.from_pandas(df))
Response

In case of a valid return value, returns a pydantic model with the following format:

>>> jsonrpc = '2.0'
... id = '1'
... signalsByInput = {
...     'INPUT_ID_1': CreateSummary(id = 'SIGNAL_ID_1', created = True),
...     'INPUT_ID_2': CreateSummary(id = 'SIGNAL_ID_2', created = True)
... }
... error = None

Where:

  • InsertResponse is a a pydantic model with field signalsByInput.

  • signalsByInput is a Dict[InputID, CreateSummary].

  • CreateSummary is a a pydantic model with field id: str and created: bool (True if a new instance was created, False is the instance already existed).

In case of the error (for example not equal length) the method return a pydantic model with the following format:

>>> jsonrpc = '2.0'
... id = '1'
... result = None
... error = Error(
...         code = '-32602',
...         message = 'Invalid params',
...         data = ErrorData(
...                     trace = <trace_id>,
...                     params = {'data.series.id': ['not same length as times']}
...         )
... )