Skip to content

Commit

Permalink
BUG: Fixed renaming of falsey names in build_table_schema (#16205)
Browse files Browse the repository at this point in the history
Closes #16203
  • Loading branch information
TomAugspurger authored May 3, 2017
1 parent 154a647 commit ae70ece
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pandas/io/json/table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def set_default_names(data):

def make_field(arr, dtype=None):
dtype = dtype or arr.dtype
field = {'name': arr.name or 'values',
if arr.name is None:
name = 'values'
else:
name = arr.name
field = {'name': name,
'type': as_json_table_type(dtype)}

if is_categorical_dtype(arr):
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/io/json/test_json_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,11 @@ def test_overlapping_names(self):
data.to_json(orient='table')

assert 'Overlapping' in str(excinfo.value)

def test_mi_falsey_name(self):
# GH 16203
df = pd.DataFrame(np.random.randn(4, 4),
index=pd.MultiIndex.from_product([('A', 'B'),
('a', 'b')]))
result = [x['name'] for x in build_table_schema(df)['fields']]
assert result == ['level_0', 'level_1', 0, 1, 2, 3]

0 comments on commit ae70ece

Please sign in to comment.