|
| 1 | +import os |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +import pandas.util._test_decorators as td |
| 6 | + |
| 7 | +from pandas import DataFrame |
| 8 | +import pandas.util.testing as tm |
| 9 | + |
| 10 | +from pandas.io.excel import ExcelFile, read_excel |
| 11 | +from pandas.io.parsers import read_csv |
| 12 | + |
| 13 | +_seriesd = tm.getSeriesData() |
| 14 | +_tsd = tm.getTimeSeriesData() |
| 15 | +_frame = DataFrame(_seriesd)[:10] |
| 16 | +_frame2 = DataFrame(_seriesd, columns=['D', 'C', 'B', 'A'])[:10] |
| 17 | +_tsframe = tm.makeTimeDataFrame()[:5] |
| 18 | +_mixed_frame = _frame.copy() |
| 19 | +_mixed_frame['foo'] = 'bar' |
| 20 | + |
| 21 | + |
| 22 | +@td.skip_if_no('xlrd', '1.0.0') |
| 23 | +class SharedItems(object): |
| 24 | + |
| 25 | + @pytest.fixture(autouse=True) |
| 26 | + def setup_method(self, datapath): |
| 27 | + self.dirpath = datapath("io", "data") |
| 28 | + self.frame = _frame.copy() |
| 29 | + self.frame2 = _frame2.copy() |
| 30 | + self.tsframe = _tsframe.copy() |
| 31 | + self.mixed_frame = _mixed_frame.copy() |
| 32 | + |
| 33 | + def get_csv_refdf(self, basename): |
| 34 | + """ |
| 35 | + Obtain the reference data from read_csv with the Python engine. |
| 36 | +
|
| 37 | + Parameters |
| 38 | + ---------- |
| 39 | +
|
| 40 | + basename : str |
| 41 | + File base name, excluding file extension. |
| 42 | +
|
| 43 | + Returns |
| 44 | + ------- |
| 45 | +
|
| 46 | + dfref : DataFrame |
| 47 | + """ |
| 48 | + pref = os.path.join(self.dirpath, basename + '.csv') |
| 49 | + dfref = read_csv(pref, index_col=0, parse_dates=True, engine='python') |
| 50 | + return dfref |
| 51 | + |
| 52 | + def get_excelfile(self, basename, ext): |
| 53 | + """ |
| 54 | + Return test data ExcelFile instance. |
| 55 | +
|
| 56 | + Parameters |
| 57 | + ---------- |
| 58 | +
|
| 59 | + basename : str |
| 60 | + File base name, excluding file extension. |
| 61 | +
|
| 62 | + Returns |
| 63 | + ------- |
| 64 | +
|
| 65 | + excel : io.excel.ExcelFile |
| 66 | + """ |
| 67 | + return ExcelFile(os.path.join(self.dirpath, basename + ext)) |
| 68 | + |
| 69 | + def get_exceldf(self, basename, ext, *args, **kwds): |
| 70 | + """ |
| 71 | + Return test data DataFrame. |
| 72 | +
|
| 73 | + Parameters |
| 74 | + ---------- |
| 75 | +
|
| 76 | + basename : str |
| 77 | + File base name, excluding file extension. |
| 78 | +
|
| 79 | + Returns |
| 80 | + ------- |
| 81 | +
|
| 82 | + df : DataFrame |
| 83 | + """ |
| 84 | + pth = os.path.join(self.dirpath, basename + ext) |
| 85 | + return read_excel(pth, *args, **kwds) |
0 commit comments