cognite function error

  • 29 August 2023
  • 6 replies

Badge +2

When I run the following code in Jupyter notebook in CDF, I dont get any problem and it runs fine

import pandas as pd
root_asset = 'LPM_YT_MODEL'

def handle(client, data=None, secrets=None, function_call_info=None):


ts_names_list = client.time_series.list(limit=None,asset_subtree_ids=[client.assets.list(name=root_asset)[0].id])

time_series_data_extids = ts_names_list.as_external_ids()

data_points = {ts:,start=start,end=end,) for ts in time_series_data_extids if not,start=start,end=end,).empty}



but when this is executed as cognite function, it is throwing following error


Traceback (most recent call last):
File "/home/site/wwwroot/function/", line 455, in run_handle
result = handle(*function_argument_values)
File "/home/site/wwwroot/function/", line 12, in handle
time_series_data_extids = ts_names_list.as_external_ids()
File "/home/site/wwwroot/.python_packages/lib/site-packages/cognite/client/data_classes/", line 214, in __getattribute__
attr = super().__getattribute__(item)
AttributeError: 'TimeSeriesList' object has no attribute 'as_external_ids'


Best answer by Håkon V. Treider 29 August 2023, 21:01

View original

6 replies

@eashwar11, can you please check which version each of them are running on? I am pretty sure the “as_external_ids” was a recent addition (to v6.15). You can check this with client.version. The solution is most likely to upgrade your requirements file in your Cognite function to the latest version.

Badge +2

Thanks @HaydenH . Updated the requirements with the version = 6.15.0 and the function ran till the end. 


Now I have a unique error. At the end of the function, I have a statement and this ran fine in a jupyter notebook.


This is the error I am getting. Please help. How Do i store this csv in CDF through this function.

I need to store this final dataframe into a csv.


Traceback (most recent call last):
File "/home/site/wwwroot/function/", line 455, in run_handle
result = handle(*function_argument_values)
File "/home/site/wwwroot/function/", line 57, in handle
File "/home/site/wwwroot/.python_packages/lib/site-packages/pandas/core/", line 3772, in to_csv
return DataFrameRenderer(formatter).to_csv(
File "/home/site/wwwroot/.python_packages/lib/site-packages/pandas/io/formats/", line 1186, in to_csv
File "/home/site/wwwroot/.python_packages/lib/site-packages/pandas/io/formats/", line 240, in save
with get_handle(
File "/home/site/wwwroot/.python_packages/lib/site-packages/pandas/io/", line 859, in get_handle
handle = open(
OSError: [Errno 30] Read-only file system: 'Extract_Charts.csv'


No worries @eashwar11, regarding the last error, what is in the Dataframe? Are the columns time series datapoints or is it tabular? Regardless, I would suggest you upload them as datapoints to timeseries objects or as a sequence. Then if you need the results in a csv, they can be converted, as you can use .to_pandas() and then pandas has a to_csv method. On Cognite Functions, you only have a Read-only file system, as indicated by the error.

Badge +2

Thanks @HaydenH . Customer is asking for a csv file only. The final dataframe is having a long list of columns (each column representing some specific series)

They would like to fetch the csv from CDF and then use it to analyse offline

Userlevel 4

As the error message eludes to, most of the file system is read-only, but you do have write access to the /tmp directory.

After checking the pandas documentation, I see that the .to_csv method also accepts a buffer, so you may do everything in memory and then use client.files.upload_bytes

Userlevel 4

Btw, this is a good resource for known issues with Functions: