Skip to content

Commit

Permalink
Fix print_schema() bug
Browse files Browse the repository at this point in the history
  • Loading branch information
onesuper committed Jul 18, 2019
1 parent 436f0fe commit d7246ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
13 changes: 10 additions & 3 deletions pandasticsearch/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,16 @@ def print_schema(self):
return

sys.stdout.write('{0}\n'.format(self._index))
index = list(self._mapping.values())[0] # {'index': {}}
schema = self.resolve_schema(index['mappings']['properties'])
sys.stdout.write(schema)
index_name = list(self._mapping.keys())[0]
if self._compat >= 7:
json_obj = self._mapping[index_name]["mappings"]["properties"]
sys.stdout.write(self.resolve_schema(json_obj))
else:
if self._doc_type is not None:
json_obj = self._mapping[index_name]["mappings"][self._doc_type]["properties"]
sys.stdout.write(self.resolve_schema(json_obj))
else:
raise DataFrameException('Please specify mapping for ES version under 7')

def resolve_schema(self, json_prop, res_schema="", depth=1):
for field in json_prop:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='pandasticsearch',
version='0.5.2',
version='0.5.3',
author='onesuper',
author_email='[email protected]',
packages=['pandasticsearch', 'pandasticsearch.operators'],
Expand Down
8 changes: 8 additions & 0 deletions tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ def test_columns(self):
df = create_df_from_es()
self.assertEqual(df.columns, ['a', 'b', 'c.d', 'c.e'])

def test_print_schema(self):
df = create_df_from_es()
df.print_schema()

def test_columns_after_removal_mapping(self):
df = create_df_from_es_after_removal_mapping()
self.assertEqual(df.columns, ['a', 'b', 'c.d', 'c.e'])

def test_print_schema_after_removal_mapping(self):
df = create_df_from_es_after_removal_mapping()
df.print_schema()

def test_init(self):
df = create_df_from_es()
self.assertEqual(df.to_dict(), {'size': 20})
Expand Down

0 comments on commit d7246ed

Please sign in to comment.