robertwb commented on code in PR #29169:
URL: https://github.com/apache/beam/pull/29169#discussion_r1375106335
##########
sdks/python/apache_beam/yaml/yaml_mapping.py:
##########
@@ -100,16 +80,13 @@ def __setstate__(self, state):
def row_to_dict(row):
- if (str(type(row).__name__).startswith('BeamSchema_') or
- isinstance(row, Row)):
+ if ((isinstance(row, tuple) and hasattr(row, '_asdict')) or
+ isinstance(row, beam.Row)):
row = row._asdict()
if isinstance(row, dict):
- for key, value in row.items():
- row[key] = row_to_dict(value)
+ return {key: row_to_dict(value) for key, value in row.items()}
elif not isinstance(row, str) and isinstance(row, Iterable):
- row_list = list(row)
- for idx in range(len(row_list)):
- row_list[idx] = row_to_dict(row_list[idx])
+ return [row_to_dict(value) for value in list(row)]
return row
Review Comment:
Nit. I'd put the last return in an else clause (as it's a "mutually
exclusive cases" kind of setup.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]