Fixed issue with read_json and partially missing MI names (#19177) · pandas-dev/pandas@c271d4d (original) (raw)
`@@ -451,6 +451,20 @@ def test_set_names_unset(self, idx, nm, prop):
`
451
451
`result = set_default_names(data)
`
452
452
`assert getattr(result.index, prop) == nm
`
453
453
``
``
454
`+
@pytest.mark.parametrize("idx", [
`
``
455
`+
pd.Index([], name='index'),
`
``
456
`+
pd.MultiIndex.from_arrays([['foo'], ['bar']],
`
``
457
`+
names=('level_0', 'level_1')),
`
``
458
`+
pd.MultiIndex.from_arrays([['foo'], ['bar']],
`
``
459
`+
names=('foo', 'level_1'))
`
``
460
`+
])
`
``
461
`+
def test_warns_non_roundtrippable_names(self, idx):
`
``
462
`+
GH 19130
`
``
463
`+
df = pd.DataFrame([[]], index=idx)
`
``
464
`+
df.index.name = 'index'
`
``
465
`+
with tm.assert_produces_warning():
`
``
466
`+
set_default_names(df)
`
``
467
+
454
468
`def test_timestamp_in_columns(self):
`
455
469
`df = pd.DataFrame([[1, 2]], columns=[pd.Timestamp('2016'),
`
456
470
`pd.Timedelta(10, unit='s')])
`
`@@ -481,7 +495,8 @@ def test_mi_falsey_name(self):
`
481
495
`class TestTableOrientReader(object):
`
482
496
``
483
497
`@pytest.mark.parametrize("index_nm", [
`
484
``
`-
None, "idx", pytest.param("index", marks=pytest.mark.xfail)])
`
``
498
`+
None, "idx", pytest.param("index", marks=pytest.mark.xfail),
`
``
499
`+
'level_0'])
`
485
500
`@pytest.mark.parametrize("vals", [
`
486
501
` {'ints': [1, 2, 3, 4]},
`
487
502
` {'objects': ['a', 'b', 'c', 'd']},
`
`@@ -492,7 +507,7 @@ class TestTableOrientReader(object):
`
492
507
`pytest.param({'floats': [1., 2., 3., 4.]}, marks=pytest.mark.xfail),
`
493
508
` {'floats': [1.1, 2.2, 3.3, 4.4]},
`
494
509
` {'bools': [True, False, False, True]}])
`
495
``
`-
def test_read_json_table_orient(self, index_nm, vals):
`
``
510
`+
def test_read_json_table_orient(self, index_nm, vals, recwarn):
`
496
511
`df = DataFrame(vals, index=pd.Index(range(4), name=index_nm))
`
497
512
`out = df.to_json(orient="table")
`
498
513
`result = pd.read_json(out, orient="table")
`
`@@ -504,7 +519,7 @@ def test_read_json_table_orient(self, index_nm, vals):
`
504
519
` {'timedeltas': pd.timedelta_range('1H', periods=4, freq='T')},
`
505
520
` {'timezones': pd.date_range('2016-01-01', freq='d', periods=4,
`
506
521
`tz='US/Central')}])
`
507
``
`-
def test_read_json_table_orient_raises(self, index_nm, vals):
`
``
522
`+
def test_read_json_table_orient_raises(self, index_nm, vals, recwarn):
`
508
523
`df = DataFrame(vals, index=pd.Index(range(4), name=index_nm))
`
509
524
`out = df.to_json(orient="table")
`
510
525
`with tm.assert_raises_regex(NotImplementedError, 'can not yet read '):
`
`@@ -530,7 +545,9 @@ def test_comprehensive(self):
`
530
545
`result = pd.read_json(out, orient="table")
`
531
546
`tm.assert_frame_equal(df, result)
`
532
547
``
533
``
`-
@pytest.mark.parametrize("index_names", [[None, None], ['foo', 'bar']])
`
``
548
`+
@pytest.mark.parametrize("index_names", [
`
``
549
`+
[None, None], ['foo', 'bar'], ['foo', None], [None, 'foo'],
`
``
550
`+
['index', 'foo']])
`
534
551
`def test_multiindex(self, index_names):
`
535
552
`# GH 18912
`
536
553
`df = pd.DataFrame(
`