Skip to content

Commit d791362

Browse files
gfyoungjreback
authored andcommitted
MAINT: Strip internals from TestCase class (#16016)
* MAINT: Move reset_display_options outside of TestCase * MAINT: Move round_trip_pickle outside of TestCase * MAINT: Remove all deprecated aliases from TestCase * DOC: Add doc explaining TestCase usage under pytest
1 parent c364e1d commit d791362

25 files changed

+66
-83
lines changed

pandas/tests/core/dtypes/test_dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def f():
4040
self.assertNotEqual(np.str_, self.dtype)
4141

4242
def test_pickle(self):
43-
result = self.round_trip_pickle(self.dtype)
43+
result = tm.round_trip_pickle(self.dtype)
4444
self.assertEqual(result, self.dtype)
4545

4646

pandas/tests/core/sparse/test_array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def _check_inplace_op(op):
562562

563563
def test_pickle(self):
564564
def _check_roundtrip(obj):
565-
unpickled = self.round_trip_pickle(obj)
565+
unpickled = tm.round_trip_pickle(obj)
566566
tm.assert_sp_array_equal(unpickled, obj)
567567

568568
_check_roundtrip(self.arr)

pandas/tests/core/sparse/test_frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def test_array_interface(self):
278278
def test_pickle(self):
279279

280280
def _test_roundtrip(frame, orig):
281-
result = self.round_trip_pickle(frame)
281+
result = tm.round_trip_pickle(frame)
282282
tm.assert_sp_frame_equal(frame, result)
283283
tm.assert_frame_equal(result.to_dense(), orig, check_dtype=False)
284284

pandas/tests/core/sparse/test_series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def test_to_frame(self):
390390

391391
def test_pickle(self):
392392
def _test_roundtrip(series):
393-
unpickled = self.round_trip_pickle(series)
393+
unpickled = tm.round_trip_pickle(series)
394394
tm.assert_sp_series_equal(series, unpickled)
395395
tm.assert_series_equal(series.to_dense(), unpickled.to_dense())
396396

pandas/tests/frame/test_block_internals.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,18 @@ def test_copy(self):
350350
self.assertIsNot(copy._data, self.mixed_frame._data)
351351

352352
def test_pickle(self):
353-
unpickled = self.round_trip_pickle(self.mixed_frame)
353+
unpickled = tm.round_trip_pickle(self.mixed_frame)
354354
assert_frame_equal(self.mixed_frame, unpickled)
355355

356356
# buglet
357357
self.mixed_frame._data.ndim
358358

359359
# empty
360-
unpickled = self.round_trip_pickle(self.empty)
360+
unpickled = tm.round_trip_pickle(self.empty)
361361
repr(unpickled)
362362

363363
# tz frame
364-
unpickled = self.round_trip_pickle(self.tzframe)
364+
unpickled = tm.round_trip_pickle(self.tzframe)
365365
assert_frame_equal(self.tzframe, unpickled)
366366

367367
def test_consolidate_datetime64(self):

pandas/tests/frame/test_repr_info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_repr_unsortable(self):
118118
fmt.set_option('display.max_rows', 1000, 'display.max_columns', 1000)
119119
repr(self.frame)
120120

121-
self.reset_display_options()
121+
tm.reset_display_options()
122122

123123
warnings.filters = warn_filters
124124

pandas/tests/frame/test_subclass.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_dataframe_metadata(self):
8585
self.assertEqual(df.iloc[0:1, :].testattr, 'XXX')
8686

8787
# GH10553
88-
unpickled = self.round_trip_pickle(df)
88+
unpickled = tm.round_trip_pickle(df)
8989
tm.assert_frame_equal(df, unpickled)
9090
self.assertEqual(df._metadata, unpickled._metadata)
9191
self.assertEqual(df.testattr, unpickled.testattr)

pandas/tests/indexes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setup_indices(self):
2828
setattr(self, name, idx)
2929

3030
def verify_pickle(self, index):
31-
unpickled = self.round_trip_pickle(index)
31+
unpickled = tm.round_trip_pickle(index)
3232
self.assertTrue(index.equals(unpickled))
3333

3434
def test_pickle_compat_construction(self):

pandas/tests/indexes/datetimes/test_datetime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_roundtrip_pickle_with_tz(self):
106106
# GH 8367
107107
# round-trip of timezone
108108
index = date_range('20130101', periods=3, tz='US/Eastern', name='foo')
109-
unpickled = self.round_trip_pickle(index)
109+
unpickled = tm.round_trip_pickle(index)
110110
self.assert_index_equal(index, unpickled)
111111

112112
def test_reindex_preserves_tz_if_target_is_empty_list_or_array(self):

pandas/tests/indexes/datetimes/test_ops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ def test_comparison(self):
11211121
self.assertFalse(comp[9])
11221122

11231123
def test_pickle_unpickle(self):
1124-
unpickled = self.round_trip_pickle(self.rng)
1124+
unpickled = tm.round_trip_pickle(self.rng)
11251125
self.assertIsNotNone(unpickled.offset)
11261126

11271127
def test_copy(self):
@@ -1272,7 +1272,7 @@ def test_shift(self):
12721272
self.assertEqual(shifted[0], rng[0] + CDay())
12731273

12741274
def test_pickle_unpickle(self):
1275-
unpickled = self.round_trip_pickle(self.rng)
1275+
unpickled = tm.round_trip_pickle(self.rng)
12761276
self.assertIsNotNone(unpickled.offset)
12771277

12781278
def test_summary(self):

pandas/tests/indexes/period/test_period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_pickle_compat_construction(self):
5858
def test_pickle_round_trip(self):
5959
for freq in ['D', 'M', 'Y']:
6060
idx = PeriodIndex(['2016-05-16', 'NaT', NaT, np.NaN], freq='D')
61-
result = self.round_trip_pickle(idx)
61+
result = tm.round_trip_pickle(idx)
6262
tm.assert_index_equal(result, idx)
6363

6464
def test_get_loc(self):
@@ -761,7 +761,7 @@ def test_append_concat(self):
761761
def test_pickle_freq(self):
762762
# GH2891
763763
prng = period_range('1/1/2011', '1/1/2012', freq='M')
764-
new_prng = self.round_trip_pickle(prng)
764+
new_prng = tm.round_trip_pickle(prng)
765765
self.assertEqual(new_prng.freq, offsets.MonthEnd())
766766
self.assertEqual(new_prng.freqstr, 'M')
767767

pandas/tests/indexes/test_multi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ def test_roundtrip_pickle_with_tz(self):
10441044
[[1, 2], ['a', 'b'], date_range('20130101', periods=3,
10451045
tz='US/Eastern')
10461046
], names=['one', 'two', 'three'])
1047-
unpickled = self.round_trip_pickle(index)
1047+
unpickled = tm.round_trip_pickle(index)
10481048
self.assertTrue(index.equal_levels(unpickled))
10491049

10501050
def test_from_tuples_index_values(self):
@@ -1392,7 +1392,7 @@ def test_format_sparse_config(self):
13921392
result = self.index.format()
13931393
self.assertEqual(result[1], 'foo two')
13941394

1395-
self.reset_display_options()
1395+
tm.reset_display_options()
13961396

13971397
warnings.filters = warn_filters
13981398

pandas/tests/indexes/timedeltas/test_timedelta.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def test_pass_TimedeltaIndex_to_index(self):
454454
def test_pickle(self):
455455

456456
rng = timedelta_range('1 days', periods=10)
457-
rng_p = self.round_trip_pickle(rng)
457+
rng_p = tm.round_trip_pickle(rng)
458458
tm.assert_index_equal(rng, rng_p)
459459

460460
def test_hash_error(self):

pandas/tests/io/formats/test_eng_formatting.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_eng_float_formatter(self):
3838
'3 1E+06')
3939
self.assertEqual(result, expected)
4040

41-
self.reset_display_options()
41+
tm.reset_display_options()
4242

4343
def compare(self, formatter, input, output):
4444
formatted_input = formatter(input)
@@ -185,7 +185,7 @@ def test_nan(self):
185185
fmt.set_eng_float_format(accuracy=1)
186186
result = pt.to_string()
187187
self.assertTrue('NaN' in result)
188-
self.reset_display_options()
188+
tm.reset_display_options()
189189

190190
def test_inf(self):
191191
# Issue #11981

pandas/tests/io/formats/test_format.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_eng_float_formatter(self):
138138

139139
fmt.set_eng_float_format(accuracy=0)
140140
repr(self.frame)
141-
self.reset_display_options()
141+
tm.reset_display_options()
142142

143143
def test_show_null_counts(self):
144144

@@ -1197,7 +1197,7 @@ def test_to_string_line_width_no_index(self):
11971197
self.assertEqual(df_s, expected)
11981198

11991199
def test_to_string_float_formatting(self):
1200-
self.reset_display_options()
1200+
tm.reset_display_options()
12011201
fmt.set_option('display.precision', 5, 'display.column_space', 12,
12021202
'display.notebook_repr_html', False)
12031203

@@ -1226,7 +1226,7 @@ def test_to_string_float_formatting(self):
12261226
expected = (' x\n' '0 3234.000\n' '1 0.253')
12271227
self.assertEqual(df_s, expected)
12281228

1229-
self.reset_display_options()
1229+
tm.reset_display_options()
12301230
self.assertEqual(get_option("display.precision"), 6)
12311231

12321232
df = DataFrame({'x': [1e9, 0.2512]})
@@ -1310,14 +1310,14 @@ def test_to_string_index_formatter(self):
13101310
self.assertEqual(rs, xp)
13111311

13121312
def test_to_string_left_justify_cols(self):
1313-
self.reset_display_options()
1313+
tm.reset_display_options()
13141314
df = DataFrame({'x': [3234, 0.253]})
13151315
df_s = df.to_string(justify='left')
13161316
expected = (' x \n' '0 3234.000\n' '1 0.253')
13171317
self.assertEqual(df_s, expected)
13181318

13191319
def test_to_string_format_na(self):
1320-
self.reset_display_options()
1320+
tm.reset_display_options()
13211321
df = DataFrame({'A': [np.nan, -1, -2.1234, 3, 4],
13221322
'B': [np.nan, 'foo', 'foooo', 'fooooo', 'bar']})
13231323
result = df.to_string()
@@ -1380,15 +1380,15 @@ def test_repr_html(self):
13801380
fmt.set_option('display.notebook_repr_html', False)
13811381
self.frame._repr_html_()
13821382

1383-
self.reset_display_options()
1383+
tm.reset_display_options()
13841384

13851385
df = DataFrame([[1, 2], [3, 4]])
13861386
fmt.set_option('display.show_dimensions', True)
13871387
self.assertTrue('2 rows' in df._repr_html_())
13881388
fmt.set_option('display.show_dimensions', False)
13891389
self.assertFalse('2 rows' in df._repr_html_())
13901390

1391-
self.reset_display_options()
1391+
tm.reset_display_options()
13921392

13931393
def test_repr_html_wide(self):
13941394
max_cols = get_option('display.max_columns')
@@ -1552,7 +1552,7 @@ def get_ipython():
15521552
repstr = self.frame._repr_html_()
15531553
self.assertIn('class', repstr) # info fallback
15541554

1555-
self.reset_display_options()
1555+
tm.reset_display_options()
15561556

15571557
def test_pprint_pathological_object(self):
15581558
"""

pandas/tests/scalar/test_period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ def test_multiples(self):
909909
def test_round_trip(self):
910910

911911
p = Period('2000Q1')
912-
new_p = self.round_trip_pickle(p)
912+
new_p = tm.round_trip_pickle(p)
913913
self.assertEqual(new_p, p)
914914

915915

pandas/tests/scalar/test_timedelta.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def test_overflow(self):
559559
def test_pickle(self):
560560

561561
v = Timedelta('1 days 10:11:12.0123456')
562-
v_p = self.round_trip_pickle(v)
562+
v_p = tm.round_trip_pickle(v)
563563
self.assertEqual(v, v_p)
564564

565565
def test_timedelta_hash_equality(self):

pandas/tests/series/test_io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_timeseries_periodindex(self):
134134
from pandas import period_range
135135
prng = period_range('1/1/2011', '1/1/2012', freq='M')
136136
ts = Series(np.random.randn(len(prng)), prng)
137-
new_ts = self.round_trip_pickle(ts)
137+
new_ts = tm.round_trip_pickle(ts)
138138
self.assertEqual(new_ts.index.freq, 'M')
139139

140140
def test_pickle_preserve_name(self):

pandas/tests/series/test_timeseries.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -827,19 +827,19 @@ def test_asfreq_resample_set_correct_freq(self):
827827
def test_pickle(self):
828828

829829
# GH4606
830-
p = self.round_trip_pickle(NaT)
830+
p = tm.round_trip_pickle(NaT)
831831
self.assertTrue(p is NaT)
832832

833833
idx = pd.to_datetime(['2013-01-01', NaT, '2014-01-06'])
834-
idx_p = self.round_trip_pickle(idx)
834+
idx_p = tm.round_trip_pickle(idx)
835835
self.assertTrue(idx_p[0] == idx[0])
836836
self.assertTrue(idx_p[1] is NaT)
837837
self.assertTrue(idx_p[2] == idx[2])
838838

839839
# GH11002
840840
# don't infer freq
841841
idx = date_range('1750-1-1', '2050-1-1', freq='7D')
842-
idx_p = self.round_trip_pickle(idx)
842+
idx_p = tm.round_trip_pickle(idx)
843843
tm.assert_index_equal(idx, idx_p)
844844

845845
def test_setops_preserve_freq(self):

pandas/tests/test_multilevel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _check_op(opname):
179179

180180
def test_pickle(self):
181181
def _test_roundtrip(frame):
182-
unpickled = self.round_trip_pickle(frame)
182+
unpickled = tm.round_trip_pickle(frame)
183183
tm.assert_frame_equal(frame, unpickled)
184184

185185
_test_roundtrip(self.frame)

pandas/tests/test_panel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PanelTests(object):
4343

4444
def test_pickle(self):
4545
with catch_warnings(record=True):
46-
unpickled = self.round_trip_pickle(self.panel)
46+
unpickled = tm.round_trip_pickle(self.panel)
4747
assert_frame_equal(unpickled['ItemA'], self.panel['ItemA'])
4848

4949
def test_rank(self):

pandas/tests/test_testing.py

-20
Original file line numberDiff line numberDiff line change
@@ -746,26 +746,6 @@ def test_RNGContext(self):
746746
self.assertEqual(np.random.randn(), expected0)
747747

748748

749-
class TestDeprecatedTests(tm.TestCase):
750-
751-
def test_warning(self):
752-
753-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
754-
self.assertEquals(1, 1)
755-
756-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
757-
self.assertNotEquals(1, 2)
758-
759-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
760-
self.assert_(True)
761-
762-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
763-
self.assertAlmostEquals(1.0, 1.0000000001)
764-
765-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
766-
self.assertNotAlmostEquals(1, 2)
767-
768-
769749
class TestLocale(tm.TestCase):
770750

771751
def test_locale(self):

pandas/tests/tseries/test_offsets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ def test_calendar(self):
19061906

19071907
def test_roundtrip_pickle(self):
19081908
def _check_roundtrip(obj):
1909-
unpickled = self.round_trip_pickle(obj)
1909+
unpickled = tm.round_trip_pickle(obj)
19101910
self.assertEqual(unpickled, obj)
19111911

19121912
_check_roundtrip(self.offset)
@@ -1967,7 +1967,7 @@ def test_offsets_compare_equal(self):
19671967

19681968
def test_roundtrip_pickle(self):
19691969
def _check_roundtrip(obj):
1970-
unpickled = self.round_trip_pickle(obj)
1970+
unpickled = tm.round_trip_pickle(obj)
19711971
self.assertEqual(unpickled, obj)
19721972

19731973
_check_roundtrip(self._object())

pandas/util/decorators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def deprecate_kwarg(old_arg_name, new_arg_name, mapping=None, stacklevel=2):
2424
old_arg_name : str
2525
Name of argument in function to deprecate
2626
new_arg_name : str
27-
Name of prefered argument in function
27+
Name of preferred argument in function
2828
mapping : dict or callable
2929
If mapping is present, use it to translate old arguments to
3030
new arguments. A callable must do its own value checking;

0 commit comments

Comments
 (0)