Skip to content

Commit 52ea2d8

Browse files
committed
add initial pandas HDF fileformat
1 parent c6e8357 commit 52ea2d8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pytest_arraydiff/plugin.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,41 @@ def write(filename, data, **kwargs):
153153
return np.savetxt(filename, data, **kwargs)
154154

155155

156+
class PDHDFDiff(BaseDiff):
157+
158+
extension = 'h5'
159+
160+
@staticmethod
161+
def read(filename):
162+
import pandas as pd
163+
return pd.read_hdf(filename)
164+
165+
@staticmethod
166+
def write(filename, data, **kwargs):
167+
import pandas as pd
168+
key = os.path.basename(filename).replace('.h5', '')
169+
return data.to_hdf(filename, key, **kwargs)
170+
171+
@classmethod
172+
def compare(cls, reference_file, test_file, atol=None, rtol=None):
173+
import pandas.testing as pdt
174+
175+
176+
try:
177+
pdt.assert_frame_equal(reference_file, test_file)
178+
except AssertionError as exc:
179+
message = "\n\na: {0}".format(test_file) + '\n'
180+
message += "b: {0}".format(reference_file) + '\n'
181+
message += exc.args[0]
182+
return False, message
183+
else:
184+
return True, ""
185+
186+
156187
FORMATS = {}
157188
FORMATS['fits'] = FITSDiff
158189
FORMATS['text'] = TextDiff
190+
FORMATS['pdhdf'] = PDHDFDiff
159191

160192

161193
def _download_file(url):

0 commit comments

Comments
 (0)