Skip to content

Commit

Permalink
Merge pull request #184 from martindurant/index_no_name
Browse files Browse the repository at this point in the history
Prevent pandas auto-names being given to index
  • Loading branch information
martindurant committed Jul 22, 2017
2 parents 1086272 + 83684d7 commit 8d45042
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fastparquet/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections import OrderedDict
import json
import os
import re
import six
import struct

Expand Down Expand Up @@ -500,6 +501,8 @@ def get_type(name):
dtypes.extend(['category'] * len(cs))
df, views = dataframe.empty(dtypes, size, cols=cols, index_name=index,
index_type=index_type, cats=cats)
if index and re.match(r'__index_level_\d+__', index):
df.index.name = None
return df, views


Expand Down
23 changes: 23 additions & 0 deletions fastparquet/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,26 @@ def test_index_not_in_columns(tempdir):
assert out.index.tolist() == ['x', 'y', 'z']
out = pf.to_pandas(columns=['b'], index=False)
assert out.index.tolist() == [0, 1, 2]


def test_no_index_name(tempdir):
df = pd.DataFrame({'__index_level_0__': ['x', 'y', 'z'],
'b': [4, 5, 6]}).set_index('__index_level_0__')
write(tempdir, df, file_scheme='hive')
pf = ParquetFile(tempdir)
out = pf.to_pandas()
assert out.index.name is None
assert out.index.tolist() == ['x', 'y', 'z']

df = pd.DataFrame({'__index_level_0__': ['x', 'y', 'z'],
'b': [4, 5, 6]})
write(tempdir, df, file_scheme='hive')
pf = ParquetFile(tempdir)
out = pf.to_pandas(index='__index_level_0__', columns=['b'])
assert out.index.name is None
assert out.index.tolist() == ['x', 'y', 'z']

pf = ParquetFile(tempdir)
out = pf.to_pandas()
assert out.index.name is None
assert out.index.tolist() == [0, 1, 2]

0 comments on commit 8d45042

Please sign in to comment.