Skip to content

Commit 2f108cc

Browse files
committed
add initial pandas HDF fileformat
1 parent c1779e6 commit 2f108cc

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
@@ -137,9 +137,41 @@ def write(filename, data, **kwargs):
137137
return np.savetxt(filename, data, **kwargs)
138138

139139

140+
class PDHDFDiff(BaseDiff):
141+
142+
extension = 'h5'
143+
144+
@staticmethod
145+
def read(filename):
146+
import pandas as pd
147+
return pd.read_hdf(filename)
148+
149+
@staticmethod
150+
def write(filename, data, **kwargs):
151+
import pandas as pd
152+
key = os.path.basename(filename).replace('.h5', '')
153+
return data.to_hdf(filename, key, **kwargs)
154+
155+
@classmethod
156+
def compare(cls, reference_file, test_file, atol=None, rtol=None):
157+
import pandas.testing as pdt
158+
159+
160+
try:
161+
pdt.assert_frame_equal(reference_file, test_file)
162+
except AssertionError as exc:
163+
message = "\n\na: {0}".format(test_file) + '\n'
164+
message += "b: {0}".format(reference_file) + '\n'
165+
message += exc.args[0]
166+
return False, message
167+
else:
168+
return True, ""
169+
170+
140171
FORMATS = {}
141172
FORMATS['fits'] = FITSDiff
142173
FORMATS['text'] = TextDiff
174+
FORMATS['pdhdf'] = PDHDFDiff
143175

144176

145177
def _download_file(url):

0 commit comments

Comments
 (0)