Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type error on inst to pd with single prop and expand True #1947

Merged
merged 4 commits into from
Sep 30, 2024

Conversation

haakonvt
Copy link
Contributor

@haakonvt haakonvt commented Sep 26, 2024

---------------------------------------------------------------------------
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

@haakonvt haakonvt requested review from a team as code owners September 26, 2024 20:51
Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.22%. Comparing base (970fedb) to head (8d56821).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1947      +/-   ##
==========================================
- Coverage   90.22%   90.22%   -0.01%     
==========================================
  Files         135      135              
  Lines       21577    21577              
==========================================
- Hits        19468    19467       -1     
- Misses       2109     2110       +1     
Files with missing lines Coverage Δ
cognite/client/_version.py 100.00% <100.00%> (ø)
...ite/client/data_classes/data_modeling/instances.py 90.97% <100.00%> (ø)

... and 2 files with indirect coverage changes

@haakonvt haakonvt force-pushed the fix-single-prop-inst-to-pandas branch from fb75124 to 8b11bb3 Compare September 26, 2024 21:16
@haakonvt haakonvt force-pushed the fix-single-prop-inst-to-pandas branch from c759e94 to 8d56821 Compare September 30, 2024 09:47
@haakonvt haakonvt enabled auto-merge (squash) September 30, 2024 09:47
@haakonvt haakonvt merged commit 1adecd9 into master Sep 30, 2024
13 checks passed
@haakonvt haakonvt deleted the fix-single-prop-inst-to-pandas branch September 30, 2024 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants