Skip to content

Commit 7f5ca83

Browse files
committed
add tests and fix comparer for pandas HDF
1 parent 30974dc commit 7f5ca83

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ in cases where the arrays are too large to conveniently hard-code them
99
in the tests (e.g. ``np.testing.assert_allclose(x, [1, 2, 3])``).
1010

1111
The basic idea is that you can write a test that generates a Numpy array (or
12-
other related objects depending on the format). You can then either run the
12+
other related objects depending on the format, e.g. pandas DataFrame).
13+
You can then either run the
1314
tests in a mode to **generate** reference files from the arrays, or you can run
1415
the tests in **comparison** mode, which will compare the results of the tests to
1516
the reference ones within some tolerance.
@@ -19,6 +20,7 @@ At the moment, the supported file formats for the reference files are:
1920
- A plain text-based format (based on Numpy ``loadtxt`` output)
2021
- The FITS format (requires `astropy <http://www.astropy.org>`__). With this
2122
format, tests can return either a Numpy array for a FITS HDU object.
23+
- A pandas HDF5 format using the pandas HDFStore
2224

2325
For more information on how to write tests to do this, see the **Using**
2426
section below.

pytest_arraydiff/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ def write(filename, data, **kwargs):
172172
@classmethod
173173
def compare(cls, reference_file, test_file, atol=None, rtol=None):
174174
import pandas.testing as pdt
175+
import pandas as pd
175176

176-
177+
ref_data = pd.read_hdf(reference_file)
178+
test_data = pd.read_hdf(test_file)
177179
try:
178-
pdt.assert_frame_equal(reference_file, test_file)
180+
pdt.assert_frame_equal(ref_data, test_data)
179181
except AssertionError as exc:
180182
message = "\n\na: {0}".format(test_file) + '\n'
181183
message += "b: {0}".format(reference_file) + '\n'

tests/test_pytest_arraydiff.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def test_succeeds_func_default():
2020
def test_succeeds_func_text():
2121
return np.arange(3 * 5).reshape((3, 5))
2222

23+
@pytest.mark.array_compare(file_format='pdhdf', reference_dir=reference_dir)
24+
def test_succeeds_func_pdhdf():
25+
import pandas as pd
26+
return pd.DataFrame(data=np.arange(20), columns=['test_data'])
2327

2428
@pytest.mark.array_compare(file_format='fits', reference_dir=reference_dir)
2529
def test_succeeds_func_fits():

0 commit comments

Comments
 (0)