Skip to content

Commit 30974dc

Browse files
committed
add initial pandas HDF fileformat
1 parent efc0578 commit 30974dc

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

156156

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

161193

162194
def _download_file(url):

0 commit comments

Comments
 (0)