diff --git a/pandas/tests/io/test_common.py b/pandas/tests/io/test_common.py index 289f86eb2dc53..b527e3c5dc254 100644 --- a/pandas/tests/io/test_common.py +++ b/pandas/tests/io/test_common.py @@ -143,7 +143,6 @@ def test_read_fspath_all(self, reader, module, path): ('to_csv', {}, 'os'), ('to_excel', {'engine': 'xlwt'}, 'xlwt'), ('to_feather', {}, 'feather'), - ('to_hdf', {'key': 'bar', 'mode': 'w'}, 'tables'), ('to_html', {}, 'os'), ('to_json', {}, 'os'), ('to_latex', {}, 'os'), @@ -171,6 +170,26 @@ def test_write_fspath_all(self, writer_name, writer_kwargs, module): assert result == expected + def test_write_fspath_hdf5(self): + # Same test as write_fspath_all, except HDF5 files aren't + # necessarily byte-for-byte identical for a given dataframe, so we'll + # have to read and compare equality + pytest.importorskip('tables') + + df = pd.DataFrame({"A": [1, 2]}) + p1 = tm.ensure_clean('string') + p2 = tm.ensure_clean('fspath') + + with p1 as string, p2 as fspath: + mypath = CustomFSPath(fspath) + df.to_hdf(mypath, key='bar') + df.to_hdf(string, key='bar') + + result = pd.read_hdf(fspath, key='bar') + expected = pd.read_hdf(string, key='bar') + + tm.assert_frame_equal(result, expected) + class TestMMapWrapper(object):