Skip to content

Commit

Permalink
TST: Make HDF5 fspath write test robust (#16575)
Browse files Browse the repository at this point in the history
The test_write_fspath_all test would fail on the HDF5 example
occasionally (about 1/100 in my experience). Apparently you don't get an
identical HDF5 every single time. This refactors that test out to its own where
we write and read both versions, and compare equality that way.
  • Loading branch information
TomAugspurger authored and jreback committed Jun 1, 2017
1 parent 4ec98d8 commit a19f9fa
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit a19f9fa

Please sign in to comment.