Solved

Issue With The Asset Creation Task in Data Engineer Basics - Integrate

  • 11 January 2024
  • 4 replies
  • 94 views

Badge +3

I’m trying to create assets as mentioned in the ## 2. Create The Asset Hierarchy section of the Hands on tasks but I’m getting an error, although I have checked the solution and it’s exactly the same solution you have provided.

The task says:

For each geographical region, create a corresponding CDF asset that is under the "global" root asset and is associated with the "world_info" data set.

My solution:

list = []

for region in df['region'].unique():

      asset = Asset(name=region, parent_id=14499569942375, data_set_id=621288550636820)

      list.append(asset)

client.assets.create(list)

The error message i’m getting when running the above code:
ValueError Traceback (most recent call last) Cell In[100], line 6 3 asset = Asset(name=region, parent_id=14499569942375, data_set_id=621288550636820) 4 list.append(asset) ----> 6 client.assets.create(list) File ~/workspace/using-cognite-python-sdk/.venv/lib/python3.10/site-packages/cognite/client/_api/assets.py:432, in AssetsAPI.create(self, asset) 402 """`Create one or more assets. <https://docs.cognite.com/api/v1/#operation/createAssets>`_ 403 404 You can create an arbitrary number of assets, and the SDK will split the request into multiple requests. (...) 429 >>> res = c.assets.create(asset) 430 """ 431 utils._auxiliary.assert_type(asset, "asset", [Asset, Sequence]) --> 432 return self._create_multiple(list_cls=AssetList, resource_cls=Asset, items=asset) File ~/workspace/using-cognite-python-sdk/.venv/lib/python3.10/site-packages/cognite/client/_api_client.py:649, in APIClient._create_multiple(self, items, list_cls, resource_cls, resource_path, params, headers, extra_body_fields, limit) 646 return dumped 647 return el --> 649 summary.raise_compound_exception_if_failed_tasks( 650 task_unwrap_fn=lambda task: task[1]["items"], 651 task_list_element_unwrap_fn=unwrap_element, 652 str_format_element_fn=str_format_element, 653 )

...

255 self.key_separator, self.item_separator, self.sort_keys, 256 self.skipkeys, _one_shot) --> 257 return _iterencode(o, 0)

ValueError: Out of range float values are not JSON compliant. Make sure your data does not contain NaN(s) or +/- Inf!

icon

Best answer by Dilini Fernando 29 February 2024, 12:15

View original

4 replies

Userlevel 4
Badge

The error message is very specific here so I expect you have a NaN value for one of the regions (which in pandas world is equivalent to missing)

Userlevel 1
Badge +2

As Håkon mention in the above comment, the error indicates that your data contains NaNs (Not a Number) or infinite values (+/- Inf), which are not allowed in JSON format. The problem lies probably in your df['region'].unique(). Before creating assets, ensure that the df['region'] column does not contain any NaNs or infinite values.

Here is an example of a solution: 
​​​​​​# handle infinite values

df = df.replace([np.inf, -np.inf], np.nan)

# Replace NaNs with a placeholder string

df['region'] = df['region'].fillna('Unknown')

# Convert 'region' values to string if they are not already

df['region'] = df['region'].astype(str)



assets_list = []

for region in df['region'].unique():

    asset = Asset(name=region, parent_id=14499569942375, data_set_id=621288550636820)

    assets_list.append(asset)



client.assets.create(assets_list)

Userlevel 4
Badge +2

Hi @Rawan Altaha,

I just wanted to check in and see if the information Andrian provided was helpful. Let me know if there is anything else we can assist you with.

Br,
Dilini 

Userlevel 4
Badge +2

Hi @Rawan Altaha,

I hope the above helped. As of now, I’m closing this topic. Please feel free to create a new post if you have any questions. 

Reply