cognite-sdk-python
cognite-sdk-python copied to clipboard
fix type error on inst to pd with single prop and expand True
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File /lib/python3.12/site-packages/IPython/core/formatters.py:347, in BaseFormatter.__call__(self, obj)
345 method = get_real_method(obj, self.print_method)
346 if method is not None:
--> 347 return method()
348 return None
349 else:
File /lib/python3.12/site-packages/cognite/client/data_classes/_base.py:239, in CogniteResource._repr_html_(self)
238 def _repr_html_(self) -> str:
--> 239 return notebook_display_with_fallback(self)
File /lib/python3.12/site-packages/cognite/client/utils/_pandas_helpers.py:99, in notebook_display_with_fallback(inst, **kwargs)
97 kwargs["expand_properties"] = True
98 try:
---> 99 return inst.to_pandas(**kwargs)._repr_html_()
100 except CogniteImportError:
101 warnings.warn(
102 "The 'cognite-sdk' depends on 'pandas' for pretty-printing objects like 'Asset' or 'DatapointsList' in "
103 "(Jupyter) notebooks and similar environments. Consider installing it! Using fallback method.",
104 UserWarning,
105 )
File /lib/python3.12/site-packages/cognite/client/data_classes/data_modeling/instances.py:475, in Instance.to_pandas(self, ignore, camel_case, convert_timestamps, expand_properties, remove_property_prefix, **kwargs)
470 else:
471 warnings.warn(
472 "Can't remove view ID prefix from expanded property rows as source was not unique",
473 RuntimeWarning,
474 )
--> 475 return pd.concat((col, prop_df.T.squeeze())).to_frame(name="value")
File /lib/python3.12/site-packages/pandas/core/reshape/concat.py:380, in concat(objs, axis, join, ignore_index, keys, levels, names, verify_integrity, sort, copy)
377 elif copy and using_copy_on_write():
378 copy = False
--> 380 op = _Concatenator(
381 objs,
382 axis=axis,
383 ignore_index=ignore_index,
384 join=join,
385 keys=keys,
386 levels=levels,
387 names=names,
388 verify_integrity=verify_integrity,
389 copy=copy,
390 sort=sort,
391 )
393 return op.get_result()
File /lib/python3.12/site-packages/pandas/core/reshape/concat.py:446, in _Concatenator.__init__(self, objs, axis, join, keys, levels, names, ignore_index, verify_integrity, copy, sort)
443 objs, keys = self._clean_keys_and_objs(objs, keys)
445 # figure out what our result ndim is going to be
--> 446 ndims = self._get_ndims(objs)
447 sample, objs = self._get_sample_object(objs, ndims, keys, names, levels)
449 # Standardize axis parameter to int
File /lib/python3.12/site-packages/pandas/core/reshape/concat.py:487, in _Concatenator._get_ndims(self, objs)
482 if not isinstance(obj, (ABCSeries, ABCDataFrame)):
483 msg = (
484 f"cannot concatenate object of type '{type(obj)}'; "
485 "only Series and DataFrame objs are valid"
486 )
--> 487 raise TypeError(msg)
489 ndims.add(obj.ndim)
490 return ndims
TypeError: cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid