Skip to content

Commit ae70ece

Browse files
BUG: Fixed renaming of falsey names in build_table_schema (#16205)
Closes #16203
1 parent 154a647 commit ae70ece

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas/io/json/table_schema.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ def set_default_names(data):
7676

7777
def make_field(arr, dtype=None):
7878
dtype = dtype or arr.dtype
79-
field = {'name': arr.name or 'values',
79+
if arr.name is None:
80+
name = 'values'
81+
else:
82+
name = arr.name
83+
field = {'name': name,
8084
'type': as_json_table_type(dtype)}
8185

8286
if is_categorical_dtype(arr):

pandas/tests/io/json/test_json_table_schema.py

+8
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,11 @@ def test_overlapping_names(self):
461461
data.to_json(orient='table')
462462

463463
assert 'Overlapping' in str(excinfo.value)
464+
465+
def test_mi_falsey_name(self):
466+
# GH 16203
467+
df = pd.DataFrame(np.random.randn(4, 4),
468+
index=pd.MultiIndex.from_product([('A', 'B'),
469+
('a', 'b')]))
470+
result = [x['name'] for x in build_table_schema(df)['fields']]
471+
assert result == ['level_0', 'level_1', 0, 1, 2, 3]

0 commit comments

Comments
 (0)