Skip to content

Commit 081d236

Browse files
committed
add tests and fix comparer for pandas HDF
1 parent 2f108cc commit 081d236

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
@@ -15,7 +15,8 @@ in cases where the arrays are too large to conveniently hard-code them
1515
in the tests (e.g. ``np.testing.assert_allclose(x, [1, 2, 3])``).
1616

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

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

pytest_arraydiff/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ def write(filename, data, **kwargs):
155155
@classmethod
156156
def compare(cls, reference_file, test_file, atol=None, rtol=None):
157157
import pandas.testing as pdt
158+
import pandas as pd
158159

159-
160+
ref_data = pd.read_hdf(reference_file)
161+
test_data = pd.read_hdf(test_file)
160162
try:
161-
pdt.assert_frame_equal(reference_file, test_file)
163+
pdt.assert_frame_equal(ref_data, test_data)
162164
except AssertionError as exc:
163165
message = "\n\na: {0}".format(test_file) + '\n'
164166
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
@@ -17,6 +17,10 @@ def test_succeeds_func_default():
1717
def test_succeeds_func_text():
1818
return np.arange(3 * 5).reshape((3, 5))
1919

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

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

0 commit comments

Comments
 (0)