Skip to content

Instantly share code, notes, and snippets.

@shreyasms17
Last active May 1, 2021 07:54
Show Gist options
  • Save shreyasms17/41c2a61c7e8a6196965d23b39aaadfaa to your computer and use it in GitHub Desktop.
Save shreyasms17/41c2a61c7e8a6196965d23b39aaadfaa to your computer and use it in GitHub Desktop.
AutoFlatten is_leaf
def is_leaf(self, data):
'''
Description:
This function checks if the particular field in the schema is a leaf or not.
Types not considered as a leaf : struct, array
:param data: [type: dict] a dictionary containing metadata about a field
:return leaf: [type: bool] indicates whether a given field is a leaf or not
'''
try:
if isinstance(data['type'], str):
leaf = True if data['type'] != 'struct' else False
else:
leaf = True if data['type']['type'] == 'map' else False
except:
leaf = False
finally:
return leaf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment