Skip to content

Commit 1ae6384

Browse files
committed
Merge pull request #12032 from wesm/tests/test-frame-reorg-1
Break apart test_frame.py and fix all flake8 warnings
2 parents 5d8cbb2 + 91d073a commit 1ae6384

30 files changed

+18298
-17196
lines changed

pandas/io/tests/test_packers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
date_range, period_range, Index, SparseSeries, SparseDataFrame,
1313
SparsePanel)
1414
import pandas.util.testing as tm
15-
from pandas.util.testing import ensure_clean, assert_index_equal
16-
from pandas.tests.test_series import assert_series_equal
17-
from pandas.tests.test_frame import assert_frame_equal
15+
from pandas.util.testing import (ensure_clean, assert_index_equal,
16+
assert_series_equal,
17+
assert_frame_equal)
1818
from pandas.tests.test_panel import assert_panel_equal
1919

2020
import pandas

pandas/sparse/tests/test_sparse.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
from pandas.sparse.api import (SparseSeries,
3434
SparseDataFrame, SparsePanel,
3535
SparseArray)
36-
import pandas.tests.test_frame as test_frame
36+
from pandas.tests.frame.test_misc_api import (
37+
SafeForSparse as SparseFrameTests)
38+
3739
import pandas.tests.test_panel as test_panel
3840
import pandas.tests.test_series as test_series
3941

@@ -922,7 +924,7 @@ class TestSparseTimeSeries(tm.TestCase):
922924
pass
923925

924926

925-
class TestSparseDataFrame(tm.TestCase, test_frame.SafeForSparse):
927+
class TestSparseDataFrame(tm.TestCase, SparseFrameTests):
926928
klass = SparseDataFrame
927929
_multiprocess_can_split_ = True
928930

pandas/tests/frame/__init__.py

Whitespace-only changes.

pandas/tests/frame/common.py

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import numpy as np
2+
3+
from pandas import compat
4+
from pandas.util.decorators import cache_readonly
5+
import pandas.util.testing as tm
6+
import pandas as pd
7+
8+
_seriesd = tm.getSeriesData()
9+
_tsd = tm.getTimeSeriesData()
10+
11+
_frame = pd.DataFrame(_seriesd)
12+
_frame2 = pd.DataFrame(_seriesd, columns=['D', 'C', 'B', 'A'])
13+
_intframe = pd.DataFrame(dict((k, v.astype(int))
14+
for k, v in compat.iteritems(_seriesd)))
15+
16+
_tsframe = pd.DataFrame(_tsd)
17+
18+
_mixed_frame = _frame.copy()
19+
_mixed_frame['foo'] = 'bar'
20+
21+
22+
class TestData(object):
23+
24+
@cache_readonly
25+
def frame(self):
26+
return _frame.copy()
27+
28+
@cache_readonly
29+
def frame2(self):
30+
return _frame2.copy()
31+
32+
@cache_readonly
33+
def intframe(self):
34+
# force these all to int64 to avoid platform testing issues
35+
return pd.DataFrame(dict([(c, s) for c, s in
36+
compat.iteritems(_intframe)]),
37+
dtype=np.int64)
38+
39+
@cache_readonly
40+
def tsframe(self):
41+
return _tsframe.copy()
42+
43+
@cache_readonly
44+
def mixed_frame(self):
45+
return _mixed_frame.copy()
46+
47+
@cache_readonly
48+
def mixed_float(self):
49+
return pd.DataFrame({'A': _frame['A'].copy().astype('float32'),
50+
'B': _frame['B'].copy().astype('float32'),
51+
'C': _frame['C'].copy().astype('float16'),
52+
'D': _frame['D'].copy().astype('float64')})
53+
54+
@cache_readonly
55+
def mixed_float2(self):
56+
return pd.DataFrame({'A': _frame2['A'].copy().astype('float32'),
57+
'B': _frame2['B'].copy().astype('float32'),
58+
'C': _frame2['C'].copy().astype('float16'),
59+
'D': _frame2['D'].copy().astype('float64')})
60+
61+
@cache_readonly
62+
def mixed_int(self):
63+
return pd.DataFrame({'A': _intframe['A'].copy().astype('int32'),
64+
'B': np.ones(len(_intframe['B']), dtype='uint64'),
65+
'C': _intframe['C'].copy().astype('uint8'),
66+
'D': _intframe['D'].copy().astype('int64')})
67+
68+
@cache_readonly
69+
def all_mixed(self):
70+
return pd.DataFrame({'a': 1., 'b': 2, 'c': 'foo',
71+
'float32': np.array([1.] * 10, dtype='float32'),
72+
'int32': np.array([1] * 10, dtype='int32')},
73+
index=np.arange(10))
74+
75+
@cache_readonly
76+
def tzframe(self):
77+
result = pd.DataFrame({'A': pd.date_range('20130101', periods=3),
78+
'B': pd.date_range('20130101', periods=3,
79+
tz='US/Eastern'),
80+
'C': pd.date_range('20130101', periods=3,
81+
tz='CET')})
82+
result.iloc[1, 1] = pd.NaT
83+
result.iloc[1, 2] = pd.NaT
84+
return result
85+
86+
@cache_readonly
87+
def empty(self):
88+
return pd.DataFrame({})
89+
90+
@cache_readonly
91+
def ts1(self):
92+
return tm.makeTimeSeries()
93+
94+
@cache_readonly
95+
def ts2(self):
96+
return tm.makeTimeSeries()[5:]
97+
98+
@cache_readonly
99+
def simple(self):
100+
arr = np.array([[1., 2., 3.],
101+
[4., 5., 6.],
102+
[7., 8., 9.]])
103+
104+
return pd.DataFrame(arr, columns=['one', 'two', 'three'],
105+
index=['a', 'b', 'c'])
106+
107+
# self.ts3 = tm.makeTimeSeries()[-5:]
108+
# self.ts4 = tm.makeTimeSeries()[1:-1]
109+
110+
111+
def _check_mixed_float(df, dtype=None):
112+
# float16 are most likely to be upcasted to float32
113+
dtypes = dict(A='float32', B='float32', C='float16', D='float64')
114+
if isinstance(dtype, compat.string_types):
115+
dtypes = dict([(k, dtype) for k, v in dtypes.items()])
116+
elif isinstance(dtype, dict):
117+
dtypes.update(dtype)
118+
if dtypes.get('A'):
119+
assert(df.dtypes['A'] == dtypes['A'])
120+
if dtypes.get('B'):
121+
assert(df.dtypes['B'] == dtypes['B'])
122+
if dtypes.get('C'):
123+
assert(df.dtypes['C'] == dtypes['C'])
124+
if dtypes.get('D'):
125+
assert(df.dtypes['D'] == dtypes['D'])
126+
127+
128+
def _check_mixed_int(df, dtype=None):
129+
dtypes = dict(A='int32', B='uint64', C='uint8', D='int64')
130+
if isinstance(dtype, compat.string_types):
131+
dtypes = dict([(k, dtype) for k, v in dtypes.items()])
132+
elif isinstance(dtype, dict):
133+
dtypes.update(dtype)
134+
if dtypes.get('A'):
135+
assert(df.dtypes['A'] == dtypes['A'])
136+
if dtypes.get('B'):
137+
assert(df.dtypes['B'] == dtypes['B'])
138+
if dtypes.get('C'):
139+
assert(df.dtypes['C'] == dtypes['C'])
140+
if dtypes.get('D'):
141+
assert(df.dtypes['D'] == dtypes['D'])

0 commit comments

Comments
 (0)