Skip to content

Commit ef77c8f

Browse files
committed
Revert "Fixturize test_api"
This reverts commit c2ab4b5.
1 parent ba1bc23 commit ef77c8f

File tree

1 file changed

+94
-92
lines changed

1 file changed

+94
-92
lines changed

pandas/tests/frame/test_api.py

+94-92
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import pandas.util.testing as tm
2626

27+
from pandas.tests.frame.common import TestData
28+
2729

2830
class SharedWithSparse(object):
2931
"""
@@ -41,57 +43,57 @@ def _assert_series_equal(self, left, right):
4143
"""Dispatch to series class dependent assertion"""
4244
raise NotImplementedError
4345

44-
def test_copy_index_name_checking(self, float_frame):
46+
def test_copy_index_name_checking(self):
4547
# don't want to be able to modify the index stored elsewhere after
4648
# making a copy
4749
for attr in ('index', 'columns'):
48-
ind = getattr(float_frame, attr)
50+
ind = getattr(self.frame, attr)
4951
ind.name = None
50-
cp = float_frame.copy()
52+
cp = self.frame.copy()
5153
getattr(cp, attr).name = 'foo'
52-
assert getattr(float_frame, attr).name is None
54+
assert getattr(self.frame, attr).name is None
5355

54-
def test_getitem_pop_assign_name(self, float_frame):
55-
s = float_frame['A']
56+
def test_getitem_pop_assign_name(self):
57+
s = self.frame['A']
5658
assert s.name == 'A'
5759

58-
s = float_frame.pop('A')
60+
s = self.frame.pop('A')
5961
assert s.name == 'A'
6062

61-
s = float_frame.loc[:, 'B']
63+
s = self.frame.loc[:, 'B']
6264
assert s.name == 'B'
6365

6466
s2 = s.loc[:]
6567
assert s2.name == 'B'
6668

67-
def test_get_value(self, float_frame):
68-
for idx in float_frame.index:
69-
for col in float_frame.columns:
69+
def test_get_value(self):
70+
for idx in self.frame.index:
71+
for col in self.frame.columns:
7072
with tm.assert_produces_warning(FutureWarning,
7173
check_stacklevel=False):
72-
result = float_frame.get_value(idx, col)
73-
expected = float_frame[col][idx]
74+
result = self.frame.get_value(idx, col)
75+
expected = self.frame[col][idx]
7476
tm.assert_almost_equal(result, expected)
7577

76-
def test_add_prefix_suffix(self, float_frame):
77-
with_prefix = float_frame.add_prefix('foo#')
78-
expected = pd.Index(['foo#%s' % c for c in float_frame.columns])
78+
def test_add_prefix_suffix(self):
79+
with_prefix = self.frame.add_prefix('foo#')
80+
expected = pd.Index(['foo#%s' % c for c in self.frame.columns])
7981
tm.assert_index_equal(with_prefix.columns, expected)
8082

81-
with_suffix = float_frame.add_suffix('#foo')
82-
expected = pd.Index(['%s#foo' % c for c in float_frame.columns])
83+
with_suffix = self.frame.add_suffix('#foo')
84+
expected = pd.Index(['%s#foo' % c for c in self.frame.columns])
8385
tm.assert_index_equal(with_suffix.columns, expected)
8486

85-
with_pct_prefix = float_frame.add_prefix('%')
86-
expected = pd.Index(['%{}'.format(c) for c in float_frame.columns])
87+
with_pct_prefix = self.frame.add_prefix('%')
88+
expected = pd.Index(['%{}'.format(c) for c in self.frame.columns])
8789
tm.assert_index_equal(with_pct_prefix.columns, expected)
8890

89-
with_pct_suffix = float_frame.add_suffix('%')
90-
expected = pd.Index(['{}%'.format(c) for c in float_frame.columns])
91+
with_pct_suffix = self.frame.add_suffix('%')
92+
expected = pd.Index(['{}%'.format(c) for c in self.frame.columns])
9193
tm.assert_index_equal(with_pct_suffix.columns, expected)
9294

93-
def test_get_axis(self, float_frame):
94-
f = float_frame
95+
def test_get_axis(self):
96+
f = self.frame
9597
assert f._get_axis_number(0) == 0
9698
assert f._get_axis_number(1) == 1
9799
assert f._get_axis_number('index') == 0
@@ -116,13 +118,13 @@ def test_get_axis(self, float_frame):
116118
tm.assert_raises_regex(ValueError, 'No axis named',
117119
f._get_axis_number, None)
118120

119-
def test_keys(self, float_frame):
120-
getkeys = float_frame.keys
121-
assert getkeys() is float_frame.columns
121+
def test_keys(self):
122+
getkeys = self.frame.keys
123+
assert getkeys() is self.frame.columns
122124

123-
def test_column_contains_typeerror(self, float_frame):
125+
def test_column_contains_typeerror(self):
124126
try:
125-
float_frame.columns in float_frame
127+
self.frame.columns in self.frame
126128
except TypeError:
127129
pass
128130

@@ -144,40 +146,40 @@ def test_tab_completion(self):
144146
assert key not in dir(df)
145147
assert isinstance(df.__getitem__('A'), pd.DataFrame)
146148

147-
def test_not_hashable(self, empty_frame):
149+
def test_not_hashable(self):
148150
df = self.klass([1])
149151
pytest.raises(TypeError, hash, df)
150-
pytest.raises(TypeError, hash, empty_frame)
152+
pytest.raises(TypeError, hash, self.empty)
151153

152154
def test_new_empty_index(self):
153155
df1 = self.klass(randn(0, 3))
154156
df2 = self.klass(randn(0, 3))
155157
df1.index.name = 'foo'
156158
assert df2.index.name is None
157159

158-
def test_array_interface(self, float_frame):
160+
def test_array_interface(self):
159161
with np.errstate(all='ignore'):
160-
result = np.sqrt(float_frame)
161-
assert isinstance(result, type(float_frame))
162-
assert result.index is float_frame.index
163-
assert result.columns is float_frame.columns
162+
result = np.sqrt(self.frame)
163+
assert isinstance(result, type(self.frame))
164+
assert result.index is self.frame.index
165+
assert result.columns is self.frame.columns
164166

165-
self._assert_frame_equal(result, float_frame.apply(np.sqrt))
167+
self._assert_frame_equal(result, self.frame.apply(np.sqrt))
166168

167-
def test_get_agg_axis(self, float_frame):
168-
cols = float_frame._get_agg_axis(0)
169-
assert cols is float_frame.columns
169+
def test_get_agg_axis(self):
170+
cols = self.frame._get_agg_axis(0)
171+
assert cols is self.frame.columns
170172

171-
idx = float_frame._get_agg_axis(1)
172-
assert idx is float_frame.index
173+
idx = self.frame._get_agg_axis(1)
174+
assert idx is self.frame.index
173175

174-
pytest.raises(ValueError, float_frame._get_agg_axis, 2)
176+
pytest.raises(ValueError, self.frame._get_agg_axis, 2)
175177

176-
def test_nonzero(self, float_frame, float_string_frame, empty_frame):
177-
assert empty_frame.empty
178+
def test_nonzero(self):
179+
assert self.empty.empty
178180

179-
assert not float_frame.empty
180-
assert not float_string_frame.empty
181+
assert not self.frame.empty
182+
assert not self.mixed_frame.empty
181183

182184
# corner case
183185
df = DataFrame({'A': [1., 2., 3.],
@@ -200,20 +202,20 @@ def test_items(self):
200202
assert isinstance(v, Series)
201203
assert (df[k] == v).all()
202204

203-
def test_iter(self, float_frame):
204-
assert tm.equalContents(list(float_frame), float_frame.columns)
205+
def test_iter(self):
206+
assert tm.equalContents(list(self.frame), self.frame.columns)
205207

206-
def test_iterrows(self, float_frame, float_string_frame):
207-
for k, v in float_frame.iterrows():
208-
exp = float_frame.loc[k]
208+
def test_iterrows(self):
209+
for k, v in self.frame.iterrows():
210+
exp = self.frame.loc[k]
209211
self._assert_series_equal(v, exp)
210212

211-
for k, v in float_string_frame.iterrows():
212-
exp = float_string_frame.loc[k]
213+
for k, v in self.mixed_frame.iterrows():
214+
exp = self.mixed_frame.loc[k]
213215
self._assert_series_equal(v, exp)
214216

215217
def test_iterrows_iso8601(self):
216-
# GH 19671
218+
# GH19671
217219
if self.klass == SparseDataFrame:
218220
pytest.xfail(reason='SparseBlock datetime type not implemented.')
219221

@@ -224,11 +226,11 @@ def test_iterrows_iso8601(self):
224226
exp = s.loc[k]
225227
self._assert_series_equal(v, exp)
226228

227-
def test_itertuples(self, float_frame):
228-
for i, tup in enumerate(float_frame.itertuples()):
229+
def test_itertuples(self):
230+
for i, tup in enumerate(self.frame.itertuples()):
229231
s = self.klass._constructor_sliced(tup[1:])
230232
s.name = tup[0]
231-
expected = float_frame.iloc[i, :].reset_index(drop=True)
233+
expected = self.frame.iloc[i, :].reset_index(drop=True)
232234
self._assert_series_equal(s, expected)
233235

234236
df = self.klass({'floats': np.random.randn(5),
@@ -287,11 +289,11 @@ def test_sequence_like_with_categorical(self):
287289
for c, col in df.iteritems():
288290
str(s)
289291

290-
def test_len(self, float_frame):
291-
assert len(float_frame) == len(float_frame.index)
292+
def test_len(self):
293+
assert len(self.frame) == len(self.frame.index)
292294

293-
def test_values(self, float_frame, float_string_frame):
294-
frame = float_frame
295+
def test_values(self):
296+
frame = self.frame
295297
arr = frame.values
296298

297299
frame_cols = frame.columns
@@ -304,20 +306,20 @@ def test_values(self, float_frame, float_string_frame):
304306
assert value == frame[col][i]
305307

306308
# mixed type
307-
arr = float_string_frame[['foo', 'A']].values
309+
arr = self.mixed_frame[['foo', 'A']].values
308310
assert arr[0, 0] == 'bar'
309311

310312
df = self.klass({'real': [1, 2, 3], 'complex': [1j, 2j, 3j]})
311313
arr = df.values
312314
assert arr[0, 0] == 1j
313315

314316
# single block corner case
315-
arr = float_frame[['A', 'B']].values
316-
expected = float_frame.reindex(columns=['A', 'B']).values
317+
arr = self.frame[['A', 'B']].values
318+
expected = self.frame.reindex(columns=['A', 'B']).values
317319
assert_almost_equal(arr, expected)
318320

319-
def test_transpose(self, float_frame):
320-
frame = float_frame
321+
def test_transpose(self):
322+
frame = self.frame
321323
dft = frame.T
322324
for idx, series in compat.iteritems(dft):
323325
for col, value in compat.iteritems(series):
@@ -341,8 +343,8 @@ def test_swapaxes(self):
341343
self._assert_frame_equal(df, df.swapaxes(0, 0))
342344
pytest.raises(ValueError, df.swapaxes, 2, 5)
343345

344-
def test_axis_aliases(self, float_frame):
345-
f = float_frame
346+
def test_axis_aliases(self):
347+
f = self.frame
346348

347349
# reg name
348350
expected = f.sum(axis=0)
@@ -359,23 +361,23 @@ def test_class_axis(self):
359361
assert pydoc.getdoc(DataFrame.index)
360362
assert pydoc.getdoc(DataFrame.columns)
361363

362-
def test_more_values(self, float_string_frame):
363-
values = float_string_frame.values
364-
assert values.shape[1] == len(float_string_frame.columns)
364+
def test_more_values(self):
365+
values = self.mixed_frame.values
366+
assert values.shape[1] == len(self.mixed_frame.columns)
365367

366-
def test_repr_with_mi_nat(self, float_string_frame):
368+
def test_repr_with_mi_nat(self):
367369
df = self.klass({'X': [1, 2]},
368370
index=[[pd.NaT, pd.Timestamp('20130101')], ['a', 'b']])
369371
res = repr(df)
370372
exp = ' X\nNaT a 1\n2013-01-01 b 2'
371373
assert res == exp
372374

373-
def test_iteritems_names(self, float_string_frame):
374-
for k, v in compat.iteritems(float_string_frame):
375+
def test_iteritems_names(self):
376+
for k, v in compat.iteritems(self.mixed_frame):
375377
assert v.name == k
376378

377-
def test_series_put_names(self, float_string_frame):
378-
series = float_string_frame._series
379+
def test_series_put_names(self):
380+
series = self.mixed_frame._series
379381
for k, v in compat.iteritems(series):
380382
assert v.name == k
381383

@@ -406,39 +408,39 @@ def test_with_datetimelikes(self):
406408
tm.assert_series_equal(result, expected)
407409

408410

409-
class TestDataFrameMisc(SharedWithSparse):
411+
class TestDataFrameMisc(SharedWithSparse, TestData):
410412

411413
klass = DataFrame
412414
# SharedWithSparse tests use generic, klass-agnostic assertion
413415
_assert_frame_equal = staticmethod(assert_frame_equal)
414416
_assert_series_equal = staticmethod(assert_series_equal)
415417

416-
def test_values(self, float_frame):
417-
float_frame.values[:, 0] = 5.
418-
assert (float_frame.values[:, 0] == 5).all()
418+
def test_values(self):
419+
self.frame.values[:, 0] = 5.
420+
assert (self.frame.values[:, 0] == 5).all()
419421

420-
def test_as_matrix_deprecated(self, float_frame):
421-
# GH 18458
422+
def test_as_matrix_deprecated(self):
423+
# GH18458
422424
with tm.assert_produces_warning(FutureWarning):
423-
result = float_frame.as_matrix(columns=float_frame.columns.tolist())
424-
expected = float_frame.values
425+
result = self.frame.as_matrix(columns=self.frame.columns.tolist())
426+
expected = self.frame.values
425427
tm.assert_numpy_array_equal(result, expected)
426428

427-
def test_deepcopy(self, float_frame):
428-
cp = deepcopy(float_frame)
429+
def test_deepcopy(self):
430+
cp = deepcopy(self.frame)
429431
series = cp['A']
430432
series[:] = 10
431433
for idx, value in compat.iteritems(series):
432-
assert float_frame['A'][idx] != value
434+
assert self.frame['A'][idx] != value
433435

434-
def test_transpose_get_view(self, float_frame):
435-
dft = float_frame.T
436+
def test_transpose_get_view(self):
437+
dft = self.frame.T
436438
dft.values[:, 5:10] = 5
437439

438-
assert (float_frame.values[5:10] == 5).all()
440+
assert (self.frame.values[5:10] == 5).all()
439441

440442
def test_inplace_return_self(self):
441-
# GH 1893
443+
# re #1893
442444

443445
data = DataFrame({'a': ['foo', 'bar', 'baz', 'qux'],
444446
'b': [0, 0, 1, 1],

0 commit comments

Comments
 (0)