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(traces): convert (non-list) iterables to lists during protobuf construction due to potential presence of ndarray when reading from parquet files #1801

Merged
merged 6 commits into from
Nov 22, 2023

Conversation

RogerHYang
Copy link
Contributor

@RogerHYang RogerHYang commented Nov 22, 2023

resolves #1758

based on the types found in _SetStructValue which is shown below

Note that our protobuf version (3.20) does not accept tuple, so we have to convert it to list.

def _SetStructValue(struct_value, value):
  if value is None:
    struct_value.null_value = 0
  elif isinstance(value, bool):
    # Note: this check must come before the number check because in Python
    # True and False are also considered numbers.
    struct_value.bool_value = value
  elif isinstance(value, str):
    struct_value.string_value = value
  elif isinstance(value, (int, float)):
    struct_value.number_value = value
  elif isinstance(value, (dict, Struct)):
    struct_value.struct_value.Clear()
    struct_value.struct_value.update(value)
  elif isinstance(value, (list, ListValue)):
    struct_value.list_value.Clear()
    struct_value.list_value.extend(value)
  else:
    raise ValueError('Unexpected type')

Comment on lines 523 to 526
for key, value in obj.items():
if isinstance(value, Iterable) and not isinstance(value, (str, list, Mapping)):
value = list(value)
struct[key] = value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe safer to explicitly check for ndarray in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mainly it's because i don't want it as a dependency. i think Iterable is pretty safe given the exclusions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed it up a bit

@RogerHYang RogerHYang changed the title fix(traces): convert (non-list) iterables to lists during protobuf construction due to potential presence of ndarray objects when reading from parquet files fix(traces): convert (non-list) iterables to lists during protobuf construction due to potential presence of ndarray when reading from parquet files Nov 22, 2023
@RogerHYang RogerHYang merged commit ca72747 into main Nov 22, 2023
10 checks passed
@RogerHYang RogerHYang deleted the convert-iterable-to-list branch November 22, 2023 01:20
mikeldking pushed a commit that referenced this pull request Dec 1, 2023
…nstruction due to potential presence of ndarray when reading from parquet files (#1801)

* convert iterable to list

* add TypeError

* add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG] Can't launch application with imported LangChain traces
2 participants