From 2a1f1a87f03d182a89035cdf53d69589749ba5e2 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Sun, 23 Apr 2017 22:00:15 -0400 Subject: [PATCH] MAINT: Remove assertIs from testing --- pandas/tests/dtypes/test_common.py | 4 +- pandas/tests/dtypes/test_dtypes.py | 22 ++--- pandas/tests/frame/test_alter_axes.py | 2 +- pandas/tests/frame/test_api.py | 14 +-- pandas/tests/frame/test_apply.py | 19 ++-- .../tests/frame/test_axis_select_reindex.py | 2 +- pandas/tests/frame/test_indexing.py | 18 ++-- pandas/tests/frame/test_operators.py | 18 ++-- pandas/tests/groupby/test_groupby.py | 11 +-- .../tests/indexes/datetimes/test_datetime.py | 4 +- pandas/tests/indexes/datetimes/test_ops.py | 4 +- pandas/tests/indexes/datetimes/test_setops.py | 2 +- pandas/tests/indexes/datetimes/test_tools.py | 6 +- pandas/tests/indexes/period/test_indexing.py | 4 +- pandas/tests/indexes/period/test_ops.py | 20 ++--- pandas/tests/indexes/period/test_setops.py | 2 +- pandas/tests/indexes/test_base.py | 10 +-- pandas/tests/indexes/test_multi.py | 8 +- pandas/tests/indexes/test_numeric.py | 2 +- pandas/tests/indexes/test_range.py | 2 +- pandas/tests/indexes/timedeltas/test_ops.py | 4 +- pandas/tests/io/parser/parse_dates.py | 2 +- pandas/tests/io/test_packers.py | 2 +- pandas/tests/plotting/test_boxplot_method.py | 10 +-- pandas/tests/plotting/test_frame.py | 12 +-- pandas/tests/plotting/test_hist_method.py | 4 +- pandas/tests/scalar/test_period.py | 90 +++++++++---------- pandas/tests/scalar/test_timestamp.py | 3 +- pandas/tests/series/test_analytics.py | 4 +- pandas/tests/series/test_api.py | 4 +- pandas/tests/series/test_constructors.py | 4 +- pandas/tests/series/test_datetime_values.py | 2 +- pandas/tests/series/test_indexing.py | 12 +-- pandas/tests/series/test_period.py | 4 +- pandas/tests/series/test_sorting.py | 13 +-- pandas/tests/sparse/test_frame.py | 2 +- pandas/tests/sparse/test_libsparse.py | 4 +- pandas/tests/sparse/test_series.py | 2 +- pandas/tests/test_base.py | 14 +-- pandas/tests/test_categorical.py | 2 +- pandas/tests/test_internals.py | 2 +- pandas/tests/test_multilevel.py | 12 +-- pandas/tests/test_panel.py | 14 +-- pandas/tests/test_panel4d.py | 12 +-- pandas/tests/test_strings.py | 2 +- pandas/tests/test_util.py | 4 +- pandas/tests/tseries/test_timezones.py | 26 +++--- pandas/util/testing.py | 6 -- 48 files changed, 219 insertions(+), 227 deletions(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 1017f93b8241c..86233c5d2b192 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -26,7 +26,7 @@ def test_datetimetz_dtype(self): for dtype in ['datetime64[ns, US/Eastern]', 'datetime64[ns, Asia/Tokyo]', 'datetime64[ns, UTC]']: - self.assertIs(pandas_dtype(dtype), DatetimeTZDtype(dtype)) + assert pandas_dtype(dtype) is DatetimeTZDtype(dtype) self.assertEqual(pandas_dtype(dtype), DatetimeTZDtype(dtype)) self.assertEqual(pandas_dtype(dtype), dtype) @@ -36,7 +36,7 @@ def test_categorical_dtype(self): def test_period_dtype(self): for dtype in ['period[D]', 'period[3M]', 'period[U]', 'Period[D]', 'Period[3M]', 'Period[U]']: - self.assertIs(pandas_dtype(dtype), PeriodDtype(dtype)) + assert pandas_dtype(dtype) is PeriodDtype(dtype) self.assertEqual(pandas_dtype(dtype), PeriodDtype(dtype)) self.assertEqual(pandas_dtype(dtype), dtype) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 32ec1194639ae..e3bae3675a9e4 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -249,20 +249,14 @@ def test_subclass(self): self.assertTrue(issubclass(type(a), type(b))) def test_identity(self): - self.assertEqual(PeriodDtype('period[D]'), - PeriodDtype('period[D]')) - self.assertIs(PeriodDtype('period[D]'), - PeriodDtype('period[D]')) + assert PeriodDtype('period[D]') == PeriodDtype('period[D]') + assert PeriodDtype('period[D]') is PeriodDtype('period[D]') - self.assertEqual(PeriodDtype('period[3D]'), - PeriodDtype('period[3D]')) - self.assertIs(PeriodDtype('period[3D]'), - PeriodDtype('period[3D]')) + assert PeriodDtype('period[3D]') == PeriodDtype('period[3D]') + assert PeriodDtype('period[3D]') is PeriodDtype('period[3D]') - self.assertEqual(PeriodDtype('period[1S1U]'), - PeriodDtype('period[1000001U]')) - self.assertIs(PeriodDtype('period[1S1U]'), - PeriodDtype('period[1000001U]')) + assert PeriodDtype('period[1S1U]') == PeriodDtype('period[1000001U]') + assert PeriodDtype('period[1S1U]') is PeriodDtype('period[1000001U]') def test_coerce_to_dtype(self): self.assertEqual(_coerce_to_dtype('period[D]'), @@ -371,12 +365,12 @@ def test_construction(self): def test_construction_generic(self): # generic i = IntervalDtype('interval') - self.assertIs(i.subtype, None) + assert i.subtype is None self.assertTrue(is_interval_dtype(i)) self.assertTrue(str(i) == 'interval') i = IntervalDtype() - self.assertIs(i.subtype, None) + assert i.subtype is None self.assertTrue(is_interval_dtype(i)) self.assertTrue(str(i) == 'interval') diff --git a/pandas/tests/frame/test_alter_axes.py b/pandas/tests/frame/test_alter_axes.py index 1a3de7b463a19..b4b86d8ea1907 100644 --- a/pandas/tests/frame/test_alter_axes.py +++ b/pandas/tests/frame/test_alter_axes.py @@ -35,7 +35,7 @@ def test_set_index(self): # cache it _ = self.mixed_frame['foo'] # noqa self.mixed_frame.index = idx - self.assertIs(self.mixed_frame['foo'].index, idx) + assert self.mixed_frame['foo'].index is idx with assertRaisesRegexp(ValueError, 'Length mismatch'): self.mixed_frame.index = idx[::2] diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index e060e863c0431..9e16698bab39c 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -88,8 +88,8 @@ def test_get_axis(self): self.assertEqual(f._get_axis_name('rows'), 'index') self.assertEqual(f._get_axis_name('columns'), 'columns') - self.assertIs(f._get_axis(0), f.index) - self.assertIs(f._get_axis(1), f.columns) + assert f._get_axis(0) is f.index + assert f._get_axis(1) is f.columns assertRaisesRegexp(ValueError, 'No axis named', f._get_axis_number, 2) assertRaisesRegexp(ValueError, 'No axis.*foo', f._get_axis_name, 'foo') @@ -99,7 +99,7 @@ def test_get_axis(self): def test_keys(self): getkeys = self.frame.keys - self.assertIs(getkeys(), self.frame.columns) + assert getkeys() is self.frame.columns def test_column_contains_typeerror(self): try: @@ -122,17 +122,17 @@ def test_array_interface(self): with np.errstate(all='ignore'): result = np.sqrt(self.frame) assert isinstance(result, type(self.frame)) - self.assertIs(result.index, self.frame.index) - self.assertIs(result.columns, self.frame.columns) + assert result.index is self.frame.index + assert result.columns is self.frame.columns assert_frame_equal(result, self.frame.apply(np.sqrt)) def test_get_agg_axis(self): cols = self.frame._get_agg_axis(0) - self.assertIs(cols, self.frame.columns) + assert cols is self.frame.columns idx = self.frame._get_agg_axis(1) - self.assertIs(idx, self.frame.index) + assert idx is self.frame.index pytest.raises(ValueError, self.frame._get_agg_axis, 2) diff --git a/pandas/tests/frame/test_apply.py b/pandas/tests/frame/test_apply.py index d31fb4218adeb..9d0f00c6eeffe 100644 --- a/pandas/tests/frame/test_apply.py +++ b/pandas/tests/frame/test_apply.py @@ -25,29 +25,30 @@ def test_apply(self): with np.errstate(all='ignore'): # ufunc applied = self.frame.apply(np.sqrt) - assert_series_equal(np.sqrt(self.frame['A']), applied['A']) + tm.assert_series_equal(np.sqrt(self.frame['A']), applied['A']) # aggregator applied = self.frame.apply(np.mean) - self.assertEqual(applied['A'], np.mean(self.frame['A'])) + assert applied['A'] == np.mean(self.frame['A']) d = self.frame.index[0] applied = self.frame.apply(np.mean, axis=1) - self.assertEqual(applied[d], np.mean(self.frame.xs(d))) - self.assertIs(applied.index, self.frame.index) # want this + assert applied[d] == np.mean(self.frame.xs(d)) + assert applied.index is self.frame.index # want this # invalid axis df = DataFrame( [[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=['a', 'a', 'c']) pytest.raises(ValueError, df.apply, lambda x: x, 2) - # GH9573 + # see gh-9573 df = DataFrame({'c0': ['A', 'A', 'B', 'B'], 'c1': ['C', 'C', 'D', 'D']}) df = df.apply(lambda ts: ts.astype('category')) - self.assertEqual(df.shape, (4, 2)) - self.assertTrue(isinstance(df['c0'].dtype, CategoricalDtype)) - self.assertTrue(isinstance(df['c1'].dtype, CategoricalDtype)) + + assert df.shape == (4, 2) + assert isinstance(df['c0'].dtype, CategoricalDtype) + assert isinstance(df['c1'].dtype, CategoricalDtype) def test_apply_mixed_datetimelike(self): # mixed datetimelike @@ -190,7 +191,7 @@ def _checkit(axis=0, raw=False): if is_reduction: agg_axis = df._get_agg_axis(axis) assert isinstance(res, Series) - self.assertIs(res.index, agg_axis) + assert res.index is agg_axis else: assert isinstance(res, DataFrame) diff --git a/pandas/tests/frame/test_axis_select_reindex.py b/pandas/tests/frame/test_axis_select_reindex.py index 636194d32ad46..e8f34b977a707 100644 --- a/pandas/tests/frame/test_axis_select_reindex.py +++ b/pandas/tests/frame/test_axis_select_reindex.py @@ -204,7 +204,7 @@ def test_reindex(self): # Same index, copies values but not index if copy=False newFrame = self.frame.reindex(self.frame.index, copy=False) - self.assertIs(newFrame.index, self.frame.index) + assert newFrame.index is self.frame.index # length zero newFrame = self.frame.reindex([]) diff --git a/pandas/tests/frame/test_indexing.py b/pandas/tests/frame/test_indexing.py index 088f863e5358b..5f8d04fdb16bd 100644 --- a/pandas/tests/frame/test_indexing.py +++ b/pandas/tests/frame/test_indexing.py @@ -1171,29 +1171,29 @@ def test_getitem_fancy_1d(self): # return self if no slicing...for now with catch_warnings(record=True): - self.assertIs(f.ix[:, :], f) + assert f.ix[:, :] is f # low dimensional slice with catch_warnings(record=True): xs1 = f.ix[2, ['C', 'B', 'A']] xs2 = f.xs(f.index[2]).reindex(['C', 'B', 'A']) - assert_series_equal(xs1, xs2) + tm.assert_series_equal(xs1, xs2) with catch_warnings(record=True): ts1 = f.ix[5:10, 2] ts2 = f[f.columns[2]][5:10] - assert_series_equal(ts1, ts2) + tm.assert_series_equal(ts1, ts2) # positional xs with catch_warnings(record=True): xs1 = f.ix[0] xs2 = f.xs(f.index[0]) - assert_series_equal(xs1, xs2) + tm.assert_series_equal(xs1, xs2) with catch_warnings(record=True): xs1 = f.ix[f.index[5]] xs2 = f.xs(f.index[5]) - assert_series_equal(xs1, xs2) + tm.assert_series_equal(xs1, xs2) # single column with catch_warnings(record=True): @@ -1204,18 +1204,18 @@ def test_getitem_fancy_1d(self): exp = f.copy() exp.values[5] = 4 f.ix[5][:] = 4 - assert_frame_equal(exp, f) + tm.assert_frame_equal(exp, f) with catch_warnings(record=True): exp.values[:, 1] = 6 f.ix[:, 1][:] = 6 - assert_frame_equal(exp, f) + tm.assert_frame_equal(exp, f) # slice of mixed-frame with catch_warnings(record=True): xs = self.mixed_frame.ix[5] exp = self.mixed_frame.xs(self.mixed_frame.index[5]) - assert_series_equal(xs, exp) + tm.assert_series_equal(xs, exp) def test_setitem_fancy_1d(self): @@ -1676,7 +1676,7 @@ def test_set_value(self): def test_set_value_resize(self): res = self.frame.set_value('foobar', 'B', 0) - self.assertIs(res, self.frame) + assert res is self.frame self.assertEqual(res.index[-1], 'foobar') self.assertEqual(res.get_value('foobar', 'B'), 0) diff --git a/pandas/tests/frame/test_operators.py b/pandas/tests/frame/test_operators.py index 18639990662b0..3f77bc754a525 100644 --- a/pandas/tests/frame/test_operators.py +++ b/pandas/tests/frame/test_operators.py @@ -907,7 +907,7 @@ def test_combineFunc(self): _check_mixed_float(result, dtype=dict(C=None)) result = self.empty * 2 - self.assertIs(result.index, self.empty.index) + assert result.index is self.empty.index self.assertEqual(len(result.columns), 0) def test_comparisons(self): @@ -1117,16 +1117,16 @@ def test_inplace_ops_identity(self): s += 1 assert_series_equal(s, s2) assert_series_equal(s_orig + 1, s) - self.assertIs(s, s2) - self.assertIs(s._data, s2._data) + assert s is s2 + assert s._data is s2._data df = df_orig.copy() df2 = df df += 1 assert_frame_equal(df, df2) assert_frame_equal(df_orig + 1, df) - self.assertIs(df, df2) - self.assertIs(df._data, df2._data) + assert df is df2 + assert df._data is df2._data # dtype change s = s_orig.copy() @@ -1140,8 +1140,8 @@ def test_inplace_ops_identity(self): df += 1.5 assert_frame_equal(df, df2) assert_frame_equal(df_orig + 1.5, df) - self.assertIs(df, df2) - self.assertIs(df._data, df2._data) + assert df is df2 + assert df._data is df2._data # mixed dtype arr = np.random.randint(0, 10, size=5) @@ -1152,7 +1152,7 @@ def test_inplace_ops_identity(self): expected = DataFrame({'A': arr.copy() + 1, 'B': 'foo'}) assert_frame_equal(df, expected) assert_frame_equal(df2, expected) - self.assertIs(df._data, df2._data) + assert df._data is df2._data df = df_orig.copy() df2 = df @@ -1160,7 +1160,7 @@ def test_inplace_ops_identity(self): expected = DataFrame({'A': arr.copy() + 1.5, 'B': 'foo'}) assert_frame_equal(df, expected) assert_frame_equal(df2, expected) - self.assertIs(df._data, df2._data) + assert df._data is df2._data def test_alignment_non_pandas(self): index = ['A', 'B', 'C'] diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 02ef9e614150c..2d673b2dac259 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -759,17 +759,18 @@ def test_len(self): def test_groups(self): grouped = self.df.groupby(['A']) groups = grouped.groups - self.assertIs(groups, grouped.groups) # caching works + assert groups is grouped.groups # caching works for k, v in compat.iteritems(grouped.groups): - self.assertTrue((self.df.loc[v]['A'] == k).all()) + assert (self.df.loc[v]['A'] == k).all() grouped = self.df.groupby(['A', 'B']) groups = grouped.groups - self.assertIs(groups, grouped.groups) # caching works + assert groups is grouped.groups # caching works + for k, v in compat.iteritems(grouped.groups): - self.assertTrue((self.df.loc[v]['A'] == k[0]).all()) - self.assertTrue((self.df.loc[v]['B'] == k[1]).all()) + assert (self.df.loc[v]['A'] == k[0]).all() + assert (self.df.loc[v]['B'] == k[1]).all() def test_basic_regression(self): # regression diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index 31e795a80f2e6..66dcb195611e1 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -156,7 +156,7 @@ def test_time_overflow_for_32bit_machines(self): self.assertEqual(len(idx2), periods) def test_nat(self): - self.assertIs(DatetimeIndex([np.nan])[0], pd.NaT) + assert DatetimeIndex([np.nan])[0] is pd.NaT def test_ufunc_coercions(self): idx = date_range('2011-01-01', periods=3, freq='2D', name='x') @@ -617,7 +617,7 @@ def test_join_self(self): kinds = 'outer', 'inner', 'left', 'right' for kind in kinds: joined = index.join(index, how=kind) - self.assertIs(index, joined) + assert index is joined def assert_index_parameters(self, index): assert index.freq == '40960N' diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index de41f321b245b..d531d0913df77 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -879,8 +879,8 @@ def test_shift(self): tm.assert_index_equal(idx.shift(-3, freq='H'), exp) def test_nat(self): - self.assertIs(pd.DatetimeIndex._na_value, pd.NaT) - self.assertIs(pd.DatetimeIndex([])._na_value, pd.NaT) + assert pd.DatetimeIndex._na_value is pd.NaT + assert pd.DatetimeIndex([])._na_value is pd.NaT for tz in [None, 'US/Eastern', 'UTC']: idx = pd.DatetimeIndex(['2011-01-01', '2011-01-02'], tz=tz) diff --git a/pandas/tests/indexes/datetimes/test_setops.py b/pandas/tests/indexes/datetimes/test_setops.py index 3e6ed7756b9bd..84a1adce2c0aa 100644 --- a/pandas/tests/indexes/datetimes/test_setops.py +++ b/pandas/tests/indexes/datetimes/test_setops.py @@ -185,7 +185,7 @@ def test_datetimeindex_union_join_empty(self): result = dti.union(empty) assert isinstance(result, DatetimeIndex) - self.assertIs(result, result) + assert result is result result = dti.join(empty) assert isinstance(result, DatetimeIndex) diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index b7427f1935a8c..c637b36d1bbb5 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -179,14 +179,14 @@ def test_to_datetime_dt64s(self): ] for dt in in_bound_dts: - self.assertEqual(pd.to_datetime(dt), Timestamp(dt)) + assert pd.to_datetime(dt) == Timestamp(dt) oob_dts = [np.datetime64('1000-01-01'), np.datetime64('5000-01-02'), ] for dt in oob_dts: pytest.raises(ValueError, pd.to_datetime, dt, errors='raise') pytest.raises(ValueError, Timestamp, dt) - self.assertIs(pd.to_datetime(dt, errors='coerce'), NaT) + assert pd.to_datetime(dt, errors='coerce') is NaT def test_to_datetime_array_of_dt64s(self): dts = [np.datetime64('2000-01-01'), np.datetime64('2000-01-02'), ] @@ -681,7 +681,7 @@ def test_to_datetime_types(self): # empty string result = to_datetime('') - self.assertIs(result, NaT) + assert result is NaT result = to_datetime(['', '']) self.assertTrue(isnull(result).all()) diff --git a/pandas/tests/indexes/period/test_indexing.py b/pandas/tests/indexes/period/test_indexing.py index 982ac7d96a9cc..79998d5a6ad7f 100644 --- a/pandas/tests/indexes/period/test_indexing.py +++ b/pandas/tests/indexes/period/test_indexing.py @@ -121,7 +121,7 @@ def test_getitem_datetime(self): def test_getitem_nat(self): idx = pd.PeriodIndex(['2011-01', 'NaT', '2011-02'], freq='M') self.assertEqual(idx[0], pd.Period('2011-01', freq='M')) - self.assertIs(idx[1], tslib.NaT) + assert idx[1] is tslib.NaT s = pd.Series([0, 1, 2], index=idx) self.assertEqual(s[pd.NaT], 1) @@ -129,7 +129,7 @@ def test_getitem_nat(self): s = pd.Series(idx, index=idx) self.assertEqual(s[pd.Period('2011-01', freq='M')], pd.Period('2011-01', freq='M')) - self.assertIs(s[pd.NaT], tslib.NaT) + assert s[pd.NaT] is tslib.NaT def test_getitem_list_periods(self): # GH 7710 diff --git a/pandas/tests/indexes/period/test_ops.py b/pandas/tests/indexes/period/test_ops.py index 70a27eada7774..4f54f44b7bdab 100644 --- a/pandas/tests/indexes/period/test_ops.py +++ b/pandas/tests/indexes/period/test_ops.py @@ -56,13 +56,13 @@ def test_asobject_tolist(self): tm.assert_index_equal(result, expected) for i in [0, 1, 3]: self.assertEqual(result[i], expected[i]) - self.assertIs(result[2], pd.NaT) + assert result[2] is pd.NaT self.assertEqual(result.name, expected.name) result_list = idx.tolist() for i in [0, 1, 3]: self.assertEqual(result_list[i], expected_list[i]) - self.assertIs(result_list[2], pd.NaT) + assert result_list[2] is pd.NaT def test_minmax(self): @@ -88,15 +88,15 @@ def test_minmax(self): # Return NaT obj = PeriodIndex([], freq='M') result = getattr(obj, op)() - self.assertIs(result, tslib.NaT) + assert result is tslib.NaT obj = PeriodIndex([pd.NaT], freq='M') result = getattr(obj, op)() - self.assertIs(result, tslib.NaT) + assert result is tslib.NaT obj = PeriodIndex([pd.NaT, pd.NaT, pd.NaT], freq='M') result = getattr(obj, op)() - self.assertIs(result, tslib.NaT) + assert result is tslib.NaT def test_numpy_minmax(self): pr = pd.period_range(start='2016-01-15', end='2016-01-20') @@ -787,8 +787,8 @@ def test_repeat(self): tm.assert_index_equal(res, exp) def test_nat(self): - self.assertIs(pd.PeriodIndex._na_value, pd.NaT) - self.assertIs(pd.PeriodIndex([], freq='M')._na_value, pd.NaT) + assert pd.PeriodIndex._na_value is pd.NaT + assert pd.PeriodIndex([], freq='M')._na_value is pd.NaT idx = pd.PeriodIndex(['2011-01-01', '2011-01-02'], freq='D') self.assertTrue(idx._can_hold_na) @@ -898,7 +898,7 @@ def test_pi_ops_errors(self): np.add(obj, ng) if _np_version_under1p10: - self.assertIs(np.add(ng, obj), NotImplemented) + assert np.add(ng, obj) is NotImplemented else: with pytest.raises(TypeError): np.add(ng, obj) @@ -907,7 +907,7 @@ def test_pi_ops_errors(self): np.subtract(obj, ng) if _np_version_under1p10: - self.assertIs(np.subtract(ng, obj), NotImplemented) + assert np.subtract(ng, obj) is NotImplemented else: with pytest.raises(TypeError): np.subtract(ng, obj) @@ -1014,7 +1014,7 @@ def test_pi_sub_period(self): result = np.subtract(pd.Period('2012-01', freq='M'), idx) if _np_version_under1p10: - self.assertIs(result, NotImplemented) + assert result is NotImplemented else: tm.assert_index_equal(result, exp) diff --git a/pandas/tests/indexes/period/test_setops.py b/pandas/tests/indexes/period/test_setops.py index 54dafd832fd23..97f9cff2d193e 100644 --- a/pandas/tests/indexes/period/test_setops.py +++ b/pandas/tests/indexes/period/test_setops.py @@ -31,7 +31,7 @@ def test_join_self(self): for kind in ['inner', 'outer', 'left', 'right']: res = index.join(index, how=kind) - self.assertIs(index, res) + assert index is res def test_join_does_not_recur(self): df = tm.makeCustomDataframe( diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 91d5068ee9f19..2b6d69a90a55f 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -608,7 +608,7 @@ def test_intersection(self): # Corner cases inter = first.intersection(first) - self.assertIs(inter, first) + assert inter is first idx1 = Index([1, 2, 3, 4, 5], name='idx') # if target has the same name, it is preserved @@ -681,13 +681,13 @@ def test_union(self): # Corner cases union = first.union(first) - self.assertIs(union, first) + assert union is first union = first.union([]) - self.assertIs(union, first) + assert union is first union = Index([]).union(first) - self.assertIs(union, first) + assert union is first # preserve names first = Index(list('ab'), name='A') @@ -1434,7 +1434,7 @@ def test_join_self(self): for kind in kinds: joined = res.join(res, how=kind) - self.assertIs(res, joined) + assert res is joined def test_str_attribute(self): # GH9068 diff --git a/pandas/tests/indexes/test_multi.py b/pandas/tests/indexes/test_multi.py index 7a9b3c1c4b5d6..34051a9749af8 100644 --- a/pandas/tests/indexes/test_multi.py +++ b/pandas/tests/indexes/test_multi.py @@ -1582,10 +1582,10 @@ def test_union(self): # corner case, pass self or empty thing: the_union = self.index.union(self.index) - self.assertIs(the_union, self.index) + assert the_union is self.index the_union = self.index.union(self.index[:0]) - self.assertIs(the_union, self.index) + assert the_union is self.index # won't work in python 3 # tuples = self.index.values @@ -1614,7 +1614,7 @@ def test_intersection(self): # corner case, pass self the_int = self.index.intersection(self.index) - self.assertIs(the_int, self.index) + assert the_int is self.index # empty intersection: disjoint empty = self.index[:2] & self.index[2:] @@ -2039,7 +2039,7 @@ def test_join_self(self): for kind in kinds: res = self.index joined = res.join(res, how=kind) - self.assertIs(res, joined) + assert res is joined def test_join_multi(self): # GH 10665 diff --git a/pandas/tests/indexes/test_numeric.py b/pandas/tests/indexes/test_numeric.py index 56e0d858f1f0f..f0c42a3dae239 100644 --- a/pandas/tests/indexes/test_numeric.py +++ b/pandas/tests/indexes/test_numeric.py @@ -518,7 +518,7 @@ def test_join_self(self): kinds = 'outer', 'inner', 'left', 'right' for kind in kinds: joined = self.index.join(self.index, how=kind) - self.assertIs(self.index, joined) + assert self.index is joined def test_union_noncomparable(self): from datetime import datetime, timedelta diff --git a/pandas/tests/indexes/test_range.py b/pandas/tests/indexes/test_range.py index 4b622ad3fce49..6f87687f822e9 100644 --- a/pandas/tests/indexes/test_range.py +++ b/pandas/tests/indexes/test_range.py @@ -573,7 +573,7 @@ def test_join_self(self): kinds = 'outer', 'inner', 'left', 'right' for kind in kinds: joined = self.index.join(self.index, how=kind) - self.assertIs(self.index, joined) + assert self.index is joined def test_intersection(self): # intersect with Int64Index diff --git a/pandas/tests/indexes/timedeltas/test_ops.py b/pandas/tests/indexes/timedeltas/test_ops.py index a847467518b92..6da6653b752c9 100644 --- a/pandas/tests/indexes/timedeltas/test_ops.py +++ b/pandas/tests/indexes/timedeltas/test_ops.py @@ -819,8 +819,8 @@ def test_repeat(self): assert res.freq is None def test_nat(self): - self.assertIs(pd.TimedeltaIndex._na_value, pd.NaT) - self.assertIs(pd.TimedeltaIndex([])._na_value, pd.NaT) + assert pd.TimedeltaIndex._na_value is pd.NaT + assert pd.TimedeltaIndex([])._na_value is pd.NaT idx = pd.TimedeltaIndex(['1 days', '2 days']) self.assertTrue(idx._can_hold_na) diff --git a/pandas/tests/io/parser/parse_dates.py b/pandas/tests/io/parser/parse_dates.py index b7147cd77f4f6..f0a1f58be4026 100644 --- a/pandas/tests/io/parser/parse_dates.py +++ b/pandas/tests/io/parser/parse_dates.py @@ -363,7 +363,7 @@ def test_parse_tz_aware(self): stamp = result.index[0] self.assertEqual(stamp.minute, 39) try: - self.assertIs(result.index.tz, pytz.utc) + assert result.index.tz is pytz.utc except AssertionError: # hello Yaroslav arr = result.index.to_pydatetime() result = tools.to_datetime(arr, utc=True)[0] diff --git a/pandas/tests/io/test_packers.py b/pandas/tests/io/test_packers.py index ca6d0605c193b..f8923035b3a63 100644 --- a/pandas/tests/io/test_packers.py +++ b/pandas/tests/io/test_packers.py @@ -272,7 +272,7 @@ def test_timestamp(self): def test_nat(self): nat_rec = self.encode_decode(NaT) - self.assertIs(NaT, nat_rec) + assert NaT is nat_rec def test_datetimes(self): diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index ce341a1e02e0d..018cbbe170313 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -71,19 +71,19 @@ def test_boxplot_legacy(self): fig, ax = self.plt.subplots() axes = df.boxplot('Col1', by='X', ax=ax) ax_axes = ax.axes if self.mpl_ge_1_5_0 else ax.get_axes() - self.assertIs(ax_axes, axes) + assert ax_axes is axes fig, ax = self.plt.subplots() axes = df.groupby('Y').boxplot(ax=ax, return_type='axes') ax_axes = ax.axes if self.mpl_ge_1_5_0 else ax.get_axes() - self.assertIs(ax_axes, axes['A']) + assert ax_axes is axes['A'] # Multiple columns with an ax argument should use same figure fig, ax = self.plt.subplots() with tm.assert_produces_warning(UserWarning): axes = df.boxplot(column=['Col1', 'Col2'], by='X', ax=ax, return_type='axes') - self.assertIs(axes['Col1'].get_figure(), fig) + assert axes['Col1'].get_figure() is fig # When by is None, check that all relevant lines are present in the # dict @@ -357,7 +357,7 @@ def test_grouped_box_multiple_axes(self): returned = np.array(list(returned.values)) self._check_axes_shape(returned, axes_num=3, layout=(1, 3)) tm.assert_numpy_array_equal(returned, axes[0]) - self.assertIs(returned[0].figure, fig) + assert returned[0].figure is fig # draw on second row with tm.assert_produces_warning(UserWarning): @@ -367,7 +367,7 @@ def test_grouped_box_multiple_axes(self): returned = np.array(list(returned.values)) self._check_axes_shape(returned, axes_num=3, layout=(1, 3)) tm.assert_numpy_array_equal(returned, axes[1]) - self.assertIs(returned[0].figure, fig) + assert returned[0].figure is fig with pytest.raises(ValueError): fig, axes = self.plt.subplots(2, 3) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 0e9aa3355a658..c72bce28b5862 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -139,7 +139,7 @@ def test_plot(self): result = ax.axes else: result = ax.get_axes() # deprecated - self.assertIs(result, axes[0]) + assert result is axes[0] # GH 15516 def test_mpl2_color_cycle_str(self): @@ -443,13 +443,13 @@ def test_subplots_multiple_axes(self): sharey=False) self._check_axes_shape(returned, axes_num=3, layout=(1, 3)) self.assertEqual(returned.shape, (3, )) - self.assertIs(returned[0].figure, fig) + assert returned[0].figure is fig # draw on second row returned = df.plot(subplots=True, ax=axes[1], sharex=False, sharey=False) self._check_axes_shape(returned, axes_num=3, layout=(1, 3)) self.assertEqual(returned.shape, (3, )) - self.assertIs(returned[0].figure, fig) + assert returned[0].figure is fig self._check_axes_shape(axes, axes_num=6, layout=(2, 3)) tm.close() @@ -933,11 +933,11 @@ def test_plot_scatter_with_c(self): # verify turning off colorbar works ax = df.plot.scatter(x='x', y='y', c='z', colorbar=False) - self.assertIs(ax.collections[0].colorbar, None) + assert ax.collections[0].colorbar is None # verify that we can still plot a solid color ax = df.plot.scatter(x=0, y=1, c='red') - self.assertIs(ax.collections[0].colorbar, None) + assert ax.collections[0].colorbar is None self._check_colors(ax.collections, facecolors=['r']) # Ensure that we can pass an np.array straight through to matplotlib, @@ -2065,7 +2065,7 @@ def test_no_color_bar(self): df = self.hexbin_df ax = df.plot.hexbin(x='A', y='B', colorbar=None) - self.assertIs(ax.collections[0].colorbar, None) + assert ax.collections[0].colorbar is None @slow def test_allow_cmap(self): diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 6dd97a1181f22..79d5f74e6ea06 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -376,11 +376,11 @@ def test_grouped_hist_multiple_axes(self): returned = df.hist(column=['height', 'weight', 'category'], ax=axes[0]) self._check_axes_shape(returned, axes_num=3, layout=(1, 3)) tm.assert_numpy_array_equal(returned, axes[0]) - self.assertIs(returned[0].figure, fig) + assert returned[0].figure is fig returned = df.hist(by='classroom', ax=axes[1]) self._check_axes_shape(returned, axes_num=3, layout=(1, 3)) tm.assert_numpy_array_equal(returned, axes[1]) - self.assertIs(returned[0].figure, fig) + assert returned[0].figure is fig with pytest.raises(ValueError): fig, axes = self.plt.subplots(2, 3) diff --git a/pandas/tests/scalar/test_period.py b/pandas/tests/scalar/test_period.py index 1635d90189b50..dff954b25f839 100644 --- a/pandas/tests/scalar/test_period.py +++ b/pandas/tests/scalar/test_period.py @@ -92,25 +92,25 @@ def test_period_from_ordinal(self): def test_period_cons_nat(self): p = Period('NaT', freq='M') - self.assertIs(p, pd.NaT) + assert p is pd.NaT p = Period('nat', freq='W-SUN') - self.assertIs(p, pd.NaT) + assert p is pd.NaT p = Period(tslib.iNaT, freq='D') - self.assertIs(p, pd.NaT) + assert p is pd.NaT p = Period(tslib.iNaT, freq='3D') - self.assertIs(p, pd.NaT) + assert p is pd.NaT p = Period(tslib.iNaT, freq='1D1H') - self.assertIs(p, pd.NaT) + assert p is pd.NaT p = Period('NaT') - self.assertIs(p, pd.NaT) + assert p is pd.NaT p = Period(tslib.iNaT) - self.assertIs(p, pd.NaT) + assert p is pd.NaT def test_period_cons_mult(self): p1 = Period('2011-01', freq='3M') @@ -858,7 +858,7 @@ def test_constructor_corner(self): pytest.raises(ValueError, Period, 1.6, freq='D') pytest.raises(ValueError, Period, ordinal=1.6, freq='D') pytest.raises(ValueError, Period, ordinal=2, value=1, freq='D') - self.assertIs(Period(None), pd.NaT) + assert Period(None) is pd.NaT pytest.raises(ValueError, Period, month=1) p = Period('2007-01-01', freq='D') @@ -1020,12 +1020,12 @@ def test_add(self): def test_add_pdnat(self): p = pd.Period('2011-01', freq='M') - self.assertIs(p + pd.NaT, pd.NaT) - self.assertIs(pd.NaT + p, pd.NaT) + assert p + pd.NaT is pd.NaT + assert pd.NaT + p is pd.NaT p = pd.Period('NaT', freq='M') - self.assertIs(p + pd.NaT, pd.NaT) - self.assertIs(pd.NaT + p, pd.NaT) + assert p + pd.NaT is pd.NaT + assert pd.NaT + p is pd.NaT def test_add_raises(self): # GH 4731 @@ -1187,41 +1187,41 @@ def test_add_offset_nat(self): for freq in ['A', '2A', '3A']: p = Period('NaT', freq=freq) for o in [offsets.YearEnd(2)]: - self.assertIs(p + o, tslib.NaT) - self.assertIs(o + p, tslib.NaT) + assert p + o is tslib.NaT + assert o + p is tslib.NaT for o in [offsets.YearBegin(2), offsets.MonthBegin(1), offsets.Minute(), np.timedelta64(365, 'D'), timedelta(365)]: - self.assertIs(p + o, tslib.NaT) + assert p + o is tslib.NaT if isinstance(o, np.timedelta64): with pytest.raises(TypeError): o + p else: - self.assertIs(o + p, tslib.NaT) + assert o + p is tslib.NaT for freq in ['M', '2M', '3M']: p = Period('NaT', freq=freq) for o in [offsets.MonthEnd(2), offsets.MonthEnd(12)]: - self.assertIs(p + o, tslib.NaT) + assert p + o is tslib.NaT if isinstance(o, np.timedelta64): with pytest.raises(TypeError): o + p else: - self.assertIs(o + p, tslib.NaT) + assert o + p is tslib.NaT for o in [offsets.YearBegin(2), offsets.MonthBegin(1), offsets.Minute(), np.timedelta64(365, 'D'), timedelta(365)]: - self.assertIs(p + o, tslib.NaT) + assert p + o is tslib.NaT if isinstance(o, np.timedelta64): with pytest.raises(TypeError): o + p else: - self.assertIs(o + p, tslib.NaT) + assert o + p is tslib.NaT # freq is Tick for freq in ['D', '2D', '3D']: @@ -1229,55 +1229,55 @@ def test_add_offset_nat(self): for o in [offsets.Day(5), offsets.Hour(24), np.timedelta64(2, 'D'), np.timedelta64(3600 * 24, 's'), timedelta(-2), timedelta(hours=48)]: - self.assertIs(p + o, tslib.NaT) + assert p + o is tslib.NaT if isinstance(o, np.timedelta64): with pytest.raises(TypeError): o + p else: - self.assertIs(o + p, tslib.NaT) + assert o + p is tslib.NaT for o in [offsets.YearBegin(2), offsets.MonthBegin(1), offsets.Minute(), np.timedelta64(4, 'h'), timedelta(hours=23)]: - self.assertIs(p + o, tslib.NaT) + assert p + o is tslib.NaT if isinstance(o, np.timedelta64): with pytest.raises(TypeError): o + p else: - self.assertIs(o + p, tslib.NaT) + assert o + p is tslib.NaT for freq in ['H', '2H', '3H']: p = Period('NaT', freq=freq) for o in [offsets.Day(2), offsets.Hour(3), np.timedelta64(3, 'h'), np.timedelta64(3600, 's'), timedelta(minutes=120), timedelta(days=4, minutes=180)]: - self.assertIs(p + o, tslib.NaT) + assert p + o is tslib.NaT if not isinstance(o, np.timedelta64): - self.assertIs(o + p, tslib.NaT) + assert o + p is tslib.NaT for o in [offsets.YearBegin(2), offsets.MonthBegin(1), offsets.Minute(), np.timedelta64(3200, 's'), timedelta(hours=23, minutes=30)]: - self.assertIs(p + o, tslib.NaT) + assert p + o is tslib.NaT if isinstance(o, np.timedelta64): with pytest.raises(TypeError): o + p else: - self.assertIs(o + p, tslib.NaT) + assert o + p is tslib.NaT def test_sub_pdnat(self): # GH 13071 p = pd.Period('2011-01', freq='M') - self.assertIs(p - pd.NaT, pd.NaT) - self.assertIs(pd.NaT - p, pd.NaT) + assert p - pd.NaT is pd.NaT + assert pd.NaT - p is pd.NaT p = pd.Period('NaT', freq='M') - self.assertIs(p - pd.NaT, pd.NaT) - self.assertIs(pd.NaT - p, pd.NaT) + assert p - pd.NaT is pd.NaT + assert pd.NaT - p is pd.NaT def test_sub_offset(self): # freq is DateOffset @@ -1352,22 +1352,22 @@ def test_sub_offset_nat(self): for freq in ['A', '2A', '3A']: p = Period('NaT', freq=freq) for o in [offsets.YearEnd(2)]: - self.assertIs(p - o, tslib.NaT) + assert p - o is tslib.NaT for o in [offsets.YearBegin(2), offsets.MonthBegin(1), offsets.Minute(), np.timedelta64(365, 'D'), timedelta(365)]: - self.assertIs(p - o, tslib.NaT) + assert p - o is tslib.NaT for freq in ['M', '2M', '3M']: p = Period('NaT', freq=freq) for o in [offsets.MonthEnd(2), offsets.MonthEnd(12)]: - self.assertIs(p - o, tslib.NaT) + assert p - o is tslib.NaT for o in [offsets.YearBegin(2), offsets.MonthBegin(1), offsets.Minute(), np.timedelta64(365, 'D'), timedelta(365)]: - self.assertIs(p - o, tslib.NaT) + assert p - o is tslib.NaT # freq is Tick for freq in ['D', '2D', '3D']: @@ -1375,33 +1375,33 @@ def test_sub_offset_nat(self): for o in [offsets.Day(5), offsets.Hour(24), np.timedelta64(2, 'D'), np.timedelta64(3600 * 24, 's'), timedelta(-2), timedelta(hours=48)]: - self.assertIs(p - o, tslib.NaT) + assert p - o is tslib.NaT for o in [offsets.YearBegin(2), offsets.MonthBegin(1), offsets.Minute(), np.timedelta64(4, 'h'), timedelta(hours=23)]: - self.assertIs(p - o, tslib.NaT) + assert p - o is tslib.NaT for freq in ['H', '2H', '3H']: p = Period('NaT', freq=freq) for o in [offsets.Day(2), offsets.Hour(3), np.timedelta64(3, 'h'), np.timedelta64(3600, 's'), timedelta(minutes=120), timedelta(days=4, minutes=180)]: - self.assertIs(p - o, tslib.NaT) + assert p - o is tslib.NaT for o in [offsets.YearBegin(2), offsets.MonthBegin(1), offsets.Minute(), np.timedelta64(3200, 's'), timedelta(hours=23, minutes=30)]: - self.assertIs(p - o, tslib.NaT) + assert p - o is tslib.NaT def test_nat_ops(self): for freq in ['M', '2M', '3M']: p = Period('NaT', freq=freq) - self.assertIs(p + 1, tslib.NaT) - self.assertIs(1 + p, tslib.NaT) - self.assertIs(p - 1, tslib.NaT) - self.assertIs(p - Period('2011-01', freq=freq), tslib.NaT) - self.assertIs(Period('2011-01', freq=freq) - p, tslib.NaT) + assert p + 1 is tslib.NaT + assert 1 + p is tslib.NaT + assert p - 1 is tslib.NaT + assert p - Period('2011-01', freq=freq) is tslib.NaT + assert Period('2011-01', freq=freq) - p is tslib.NaT def test_period_ops_offset(self): p = Period('2011-04-01', freq='D') diff --git a/pandas/tests/scalar/test_timestamp.py b/pandas/tests/scalar/test_timestamp.py index 2cf40335f3ded..2b00ac68ee555 100644 --- a/pandas/tests/scalar/test_timestamp.py +++ b/pandas/tests/scalar/test_timestamp.py @@ -416,8 +416,7 @@ def test_tz_localize_nonexistent(self): tz) pytest.raises(NonExistentTimeError, ts.tz_localize, tz, errors='raise') - self.assertIs(ts.tz_localize(tz, errors='coerce'), - NaT) + assert ts.tz_localize(tz, errors='coerce') is NaT def test_tz_localize_errors_ambiguous(self): # See issue 13057 diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index eaa88da94ccd2..63e291836b472 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -1276,8 +1276,8 @@ def test_ptp(self): def test_empty_timeseries_redections_return_nat(self): # covers #11245 for dtype in ('m8[ns]', 'm8[ns]', 'M8[ns]', 'M8[ns, UTC]'): - self.assertIs(Series([], dtype=dtype).min(), pd.NaT) - self.assertIs(Series([], dtype=dtype).max(), pd.NaT) + assert Series([], dtype=dtype).min() is pd.NaT + assert Series([], dtype=dtype).max() is pd.NaT def test_unique_data_ownership(self): # it works! #1807 diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index a477bb325061f..341d4006c5fcc 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -35,7 +35,7 @@ def test_copy_index_name_checking(self): self.ts.index.name = None assert self.ts.index.name is None - self.assertIs(self.ts, self.ts) + assert self.ts is self.ts cp = self.ts.copy() cp.index.name = 'foo' @@ -203,7 +203,7 @@ def test_keys(self): # HACK: By doing this in two stages, we avoid 2to3 wrapping the call # to .keys() in a list() getkeys = self.ts.keys - self.assertIs(getkeys(), self.ts.index) + assert getkeys() is self.ts.index def test_values(self): tm.assert_almost_equal(self.ts.values, self.ts, check_dtype=False) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index e02698f96ca49..57cce1d1cf199 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -55,7 +55,7 @@ def test_constructor(self): # Mixed type Series mixed = Series(['hello', np.NaN], index=[0, 1]) self.assertEqual(mixed.dtype, np.object_) - self.assertIs(mixed[1], np.NaN) + assert mixed[1] is np.NaN self.assertFalse(self.empty.index.is_all_dates) self.assertFalse(Series({}).index.is_all_dates) @@ -226,7 +226,7 @@ def test_series_ctor_plus_datetimeindex(self): data = dict((k, 1) for k in rng) result = Series(data, index=rng) - self.assertIs(result.index, rng) + assert result.index is rng def test_constructor_default_index(self): s = Series([0, 1, 2]) diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py index ac3e3a2abbd69..ecb457b4ff1b0 100644 --- a/pandas/tests/series/test_datetime_values.py +++ b/pandas/tests/series/test_datetime_values.py @@ -368,7 +368,7 @@ def test_dt_accessor_api(self): # GH 9322 from pandas.core.indexes.accessors import ( CombinedDatetimelikeProperties, DatetimeProperties) - self.assertIs(Series.dt, CombinedDatetimelikeProperties) + assert Series.dt is CombinedDatetimelikeProperties s = Series(date_range('2000-01-01', periods=3)) assert isinstance(s.dt, DatetimeProperties) diff --git a/pandas/tests/series/test_indexing.py b/pandas/tests/series/test_indexing.py index 9872a1982a770..135e208877f2d 100644 --- a/pandas/tests/series/test_indexing.py +++ b/pandas/tests/series/test_indexing.py @@ -786,13 +786,13 @@ def test_setitem_dtypes(self): def test_set_value(self): idx = self.ts.index[10] res = self.ts.set_value(idx, 0) - self.assertIs(res, self.ts) + assert res is self.ts self.assertEqual(self.ts[idx], 0) # equiv s = self.series.copy() res = s.set_value('foobar', 0) - self.assertIs(res, s) + assert res is s self.assertEqual(res.index[-1], 'foobar') self.assertEqual(res['foobar'], 0) @@ -2659,16 +2659,16 @@ def setUp(self): def test_set_none_nan(self): self.series[3] = None - self.assertIs(self.series[3], NaT) + assert self.series[3] is NaT self.series[3:5] = None - self.assertIs(self.series[4], NaT) + assert self.series[4] is NaT self.series[5] = np.nan - self.assertIs(self.series[5], NaT) + assert self.series[5] is NaT self.series[5:7] = np.nan - self.assertIs(self.series[6], NaT) + assert self.series[6] is NaT def test_nat_operations(self): # GH 8617 diff --git a/pandas/tests/series/test_period.py b/pandas/tests/series/test_period.py index e0f1c8e060378..a67d097f341db 100644 --- a/pandas/tests/series/test_period.py +++ b/pandas/tests/series/test_period.py @@ -103,10 +103,10 @@ def test_NaT_cast(self): def test_set_none_nan(self): # currently Period is stored as object dtype, not as NaT self.series[3] = None - self.assertIs(self.series[3], None) + assert self.series[3] is None self.series[3:5] = None - self.assertIs(self.series[4], None) + assert self.series[4] is None self.series[5] = np.nan self.assertTrue(np.isnan(self.series[5])) diff --git a/pandas/tests/series/test_sorting.py b/pandas/tests/series/test_sorting.py index 7ab2ec245f611..6fe18e712a29d 100644 --- a/pandas/tests/series/test_sorting.py +++ b/pandas/tests/series/test_sorting.py @@ -129,16 +129,17 @@ def test_sort_index_inplace(self): # descending random_order = self.ts.reindex(rindex) result = random_order.sort_index(ascending=False, inplace=True) - self.assertIs(result, None, - msg='sort_index() inplace should return None') - assert_series_equal(random_order, self.ts.reindex(self.ts.index[::-1])) + + assert result is None + tm.assert_series_equal(random_order, self.ts.reindex( + self.ts.index[::-1])) # ascending random_order = self.ts.reindex(rindex) result = random_order.sort_index(ascending=True, inplace=True) - self.assertIs(result, None, - msg='sort_index() inplace should return None') - assert_series_equal(random_order, self.ts) + + assert result is None + tm.assert_series_equal(random_order, self.ts) def test_sort_index_multiindex(self): diff --git a/pandas/tests/sparse/test_frame.py b/pandas/tests/sparse/test_frame.py index ccb72d1f0d788..cf6d80e9c0133 100644 --- a/pandas/tests/sparse/test_frame.py +++ b/pandas/tests/sparse/test_frame.py @@ -593,7 +593,7 @@ def test_apply(self): exp = self.frame.to_dense().apply(np.sum, broadcast=True) tm.assert_frame_equal(broadcasted.to_dense(), exp) - self.assertIs(self.empty.apply(np.sqrt), self.empty) + assert self.empty.apply(np.sqrt) is self.empty from pandas.core import nanops applied = self.frame.apply(np.sum) diff --git a/pandas/tests/sparse/test_libsparse.py b/pandas/tests/sparse/test_libsparse.py index 00e01b8ba14bc..14038777fdd02 100644 --- a/pandas/tests/sparse/test_libsparse.py +++ b/pandas/tests/sparse/test_libsparse.py @@ -469,7 +469,7 @@ def test_to_int_index(self): def test_to_block_index(self): index = BlockIndex(10, [0, 5], [4, 5]) - self.assertIs(index.to_block_index(), index) + assert index.to_block_index() is index class TestIntIndex(tm.TestCase): @@ -554,7 +554,7 @@ def _check_case(xloc, xlen, yloc, ylen, eloc, elen): def test_to_int_index(self): index = IntIndex(10, [2, 3, 4, 5, 6]) - self.assertIs(index.to_int_index(), index) + assert index.to_int_index() is index class TestSparseOperators(tm.TestCase): diff --git a/pandas/tests/sparse/test_series.py b/pandas/tests/sparse/test_series.py index 2fd7ac3d13b98..1502aaa7e0b9e 100644 --- a/pandas/tests/sparse/test_series.py +++ b/pandas/tests/sparse/test_series.py @@ -664,7 +664,7 @@ def _check(values, index1, index2, fill_value): first_series = SparseSeries(values, sparse_index=index1, fill_value=fill_value) reindexed = first_series.sparse_reindex(index2) - self.assertIs(reindexed.sp_index, index2) + assert reindexed.sp_index is index2 int_indices1 = index1.to_int_index().indices int_indices2 = index2.to_int_index().indices diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index 5814ae3494b44..bec743fac18e1 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -525,7 +525,7 @@ def test_value_counts_unique_nunique_null(self): # unable to compare NaT / nan tm.assert_numpy_array_equal(result[1:], values[2:].asobject.values) - self.assertIs(result[0], pd.NaT) + assert result[0] is pd.NaT else: tm.assert_numpy_array_equal(result[1:], values[2:]) @@ -1018,15 +1018,17 @@ class T(NoNewAttributesMixin): pass t = T() - self.assertFalse(hasattr(t, "__frozen")) + assert not hasattr(t, "__frozen") + t.a = "test" - self.assertEqual(t.a, "test") + assert t.a == "test" + t._freeze() - # self.assertTrue("__frozen" not in dir(t)) - self.assertIs(getattr(t, "__frozen"), True) + assert "__frozen" in dir(t) + assert getattr(t, "__frozen") def f(): t.b = "test" pytest.raises(AttributeError, f) - self.assertFalse(hasattr(t, "b")) + assert not hasattr(t, "b") diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 2b9afb8e1dd6b..d516448acd876 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -4218,7 +4218,7 @@ def get_dir(s): def test_cat_accessor_api(self): # GH 9322 from pandas.core.categorical import CategoricalAccessor - self.assertIs(Series.cat, CategoricalAccessor) + assert Series.cat is CategoricalAccessor s = Series(list('aabbcde')).astype('category') assert isinstance(s.cat, CategoricalAccessor) diff --git a/pandas/tests/test_internals.py b/pandas/tests/test_internals.py index adca47488413d..f58a6d4b146bd 100644 --- a/pandas/tests/test_internals.py +++ b/pandas/tests/test_internals.py @@ -382,7 +382,7 @@ def test_pickle(self, mgr): assert_frame_equal(DataFrame(mgr), DataFrame(mgr2)) # share ref_items - # self.assertIs(mgr2.blocks[0].ref_items, mgr2.blocks[1].ref_items) + # assert mgr2.blocks[0].ref_items is mgr2.blocks[1].ref_items # GH2431 assert hasattr(mgr2, "_is_consolidated") diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index a7a80c635a364..173ac97691b3b 100755 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -198,21 +198,21 @@ def test_reindex(self): def test_reindex_preserve_levels(self): new_index = self.ymd.index[::10] chunk = self.ymd.reindex(new_index) - self.assertIs(chunk.index, new_index) + assert chunk.index is new_index chunk = self.ymd.loc[new_index] - self.assertIs(chunk.index, new_index) + assert chunk.index is new_index with catch_warnings(record=True): chunk = self.ymd.ix[new_index] - self.assertIs(chunk.index, new_index) + assert chunk.index is new_index ymdT = self.ymd.T chunk = ymdT.reindex(columns=new_index) - self.assertIs(chunk.columns, new_index) + assert chunk.columns is new_index chunk = ymdT.loc[:, new_index] - self.assertIs(chunk.columns, new_index) + assert chunk.columns is new_index def test_repr_to_string(self): repr(self.frame) @@ -939,7 +939,7 @@ def test_stack_mixed_dtype(self): stacked = df.stack() result = df['foo'].stack().sort_index() tm.assert_series_equal(stacked['foo'], result, check_names=False) - self.assertIs(result.name, None) + assert result.name is None self.assertEqual(stacked['bar'].dtype, np.float_) def test_unstack_bug(self): diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 24248d735adb0..1d0788ae160dd 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -1447,9 +1447,9 @@ def test_reindex_multi(self): major=self.panel.major_axis, minor=self.panel.minor_axis, copy=False) - self.assertIs(result.items, self.panel.items) - self.assertIs(result.major_axis, self.panel.major_axis) - self.assertIs(result.minor_axis, self.panel.minor_axis) + assert result.items is self.panel.items + assert result.major_axis is self.panel.major_axis + assert result.minor_axis is self.panel.minor_axis result = self.panel.reindex( items=self.panel.items, @@ -1612,13 +1612,13 @@ def test_truncate_fillna_bug(self): def test_swapaxes(self): with catch_warnings(record=True): result = self.panel.swapaxes('items', 'minor') - self.assertIs(result.items, self.panel.minor_axis) + assert result.items is self.panel.minor_axis result = self.panel.swapaxes('items', 'major') - self.assertIs(result.items, self.panel.major_axis) + assert result.items is self.panel.major_axis result = self.panel.swapaxes('major', 'minor') - self.assertIs(result.major_axis, self.panel.minor_axis) + assert result.major_axis is self.panel.minor_axis panel = self.panel.copy() result = panel.swapaxes('major', 'minor') @@ -1628,7 +1628,7 @@ def test_swapaxes(self): # this should also work result = self.panel.swapaxes(0, 1) - self.assertIs(result.items, self.panel.major_axis) + assert result.items is self.panel.major_axis # this works, but return a copy result = self.panel.swapaxes('items', 'items') diff --git a/pandas/tests/test_panel4d.py b/pandas/tests/test_panel4d.py index 33b17bc04cd79..05b42cdf00e94 100644 --- a/pandas/tests/test_panel4d.py +++ b/pandas/tests/test_panel4d.py @@ -867,23 +867,23 @@ def test_fillna(self): def test_swapaxes(self): with catch_warnings(record=True): result = self.panel4d.swapaxes('labels', 'items') - self.assertIs(result.items, self.panel4d.labels) + assert result.items is self.panel4d.labels result = self.panel4d.swapaxes('labels', 'minor') - self.assertIs(result.labels, self.panel4d.minor_axis) + assert result.labels is self.panel4d.minor_axis result = self.panel4d.swapaxes('items', 'minor') - self.assertIs(result.items, self.panel4d.minor_axis) + assert result.items is self.panel4d.minor_axis result = self.panel4d.swapaxes('items', 'major') - self.assertIs(result.items, self.panel4d.major_axis) + assert result.items is self.panel4d.major_axis result = self.panel4d.swapaxes('major', 'minor') - self.assertIs(result.major_axis, self.panel4d.minor_axis) + assert result.major_axis is self.panel4d.minor_axis # this should also work result = self.panel4d.swapaxes(0, 1) - self.assertIs(result.labels, self.panel4d.items) + assert result.labels is self.panel4d.items # this works, but return a copy result = self.panel4d.swapaxes('items', 'items') diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 107720d90e489..761bfa6bfe29a 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -24,7 +24,7 @@ class TestStringMethods(tm.TestCase): def test_api(self): # GH 6106, GH 9322 - self.assertIs(Series.str, strings.StringMethods) + assert Series.str is strings.StringMethods assert isinstance(Series(['']).str, strings.StringMethods) # GH 9184 diff --git a/pandas/tests/test_util.py b/pandas/tests/test_util.py index c9b2e1c9c1c75..375463ec25c36 100644 --- a/pandas/tests/test_util.py +++ b/pandas/tests/test_util.py @@ -42,7 +42,7 @@ def test_deprecate_kwarg(self): x = 78 with tm.assert_produces_warning(FutureWarning): result = self.f1(old=x) - self.assertIs(result, x) + assert result is x with tm.assert_produces_warning(None): self.f1(new=x) @@ -338,7 +338,7 @@ def test_more_than_one_ref(self): with pytest.raises(BadMove) as e: def handle_success(type_, value, tb): - self.assertIs(value.args[0], b) + assert value.args[0] is b return type(e).handle_success(e, type_, value, tb) # super e.handle_success = handle_success diff --git a/pandas/tests/tseries/test_timezones.py b/pandas/tests/tseries/test_timezones.py index 40ff2421a9f63..e3f2c242e3294 100644 --- a/pandas/tests/tseries/test_timezones.py +++ b/pandas/tests/tseries/test_timezones.py @@ -291,7 +291,7 @@ def test_create_with_tz(self): self.assertEqual(stamp, rng[1]) utc_stamp = Timestamp('3/11/2012 05:00', tz='utc') - self.assertIs(utc_stamp.tzinfo, pytz.utc) + assert utc_stamp.tzinfo is pytz.utc self.assertEqual(utc_stamp.hour, 5) stamp = Timestamp('3/11/2012 05:00').tz_localize('utc') @@ -414,7 +414,7 @@ def test_with_tz(self): # just want it to work start = datetime(2011, 3, 12, tzinfo=pytz.utc) dr = bdate_range(start, periods=50, freq=offsets.Hour()) - self.assertIs(dr.tz, pytz.utc) + assert dr.tz is pytz.utc # DateRange with naive datetimes dr = bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc) @@ -422,15 +422,15 @@ def test_with_tz(self): # normalized central = dr.tz_convert(tz) - self.assertIs(central.tz, tz) + assert central.tz is tz comp = self.localize(tz, central[0].to_pydatetime().replace( tzinfo=None)).tzinfo - self.assertIs(central[0].tz, comp) + assert central[0].tz is comp # compare vs a localized tz comp = self.localize(tz, dr[0].to_pydatetime().replace(tzinfo=None)).tzinfo - self.assertIs(central[0].tz, comp) + assert central[0].tz is comp # datetimes with tzinfo set dr = bdate_range(datetime(2005, 1, 1, tzinfo=pytz.utc), @@ -762,14 +762,14 @@ def test_convert_tz_aware_datetime_datetime(self): converted = to_datetime(dates_aware, utc=True) ex_vals = np.array([Timestamp(x).value for x in dates_aware]) tm.assert_numpy_array_equal(converted.asi8, ex_vals) - self.assertIs(converted.tz, pytz.utc) + assert converted.tz is pytz.utc def test_to_datetime_utc(self): from dateutil.parser import parse arr = np.array([parse('2012-06-13T01:39:00Z')], dtype=object) result = to_datetime(arr, utc=True) - self.assertIs(result.tz, pytz.utc) + assert result.tz is pytz.utc def test_to_datetime_tzlocal(self): from dateutil.parser import parse @@ -780,12 +780,12 @@ def test_to_datetime_tzlocal(self): arr = np.array([dt], dtype=object) result = to_datetime(arr, utc=True) - self.assertIs(result.tz, pytz.utc) + assert result.tz is pytz.utc rng = date_range('2012-11-03 03:00', '2012-11-05 03:00', tz=tzlocal()) arr = rng.to_pydatetime() result = to_datetime(arr, utc=True) - self.assertIs(result.tz, pytz.utc) + assert result.tz is pytz.utc def test_frame_no_datetime64_dtype(self): @@ -1554,18 +1554,18 @@ def test_equal_join_ensure_utc(self): ts_moscow = ts.tz_convert('Europe/Moscow') result = ts + ts_moscow - self.assertIs(result.index.tz, pytz.utc) + assert result.index.tz is pytz.utc result = ts_moscow + ts - self.assertIs(result.index.tz, pytz.utc) + assert result.index.tz is pytz.utc df = DataFrame({'a': ts}) df_moscow = df.tz_convert('Europe/Moscow') result = df + df_moscow - self.assertIs(result.index.tz, pytz.utc) + assert result.index.tz is pytz.utc result = df_moscow + df - self.assertIs(result.index.tz, pytz.utc) + assert result.index.tz is pytz.utc def test_arith_utc_convert(self): rng = date_range('1/1/2011', periods=100, freq='H', tz='utc') diff --git a/pandas/util/testing.py b/pandas/util/testing.py index b28bd6a696bda..08b298fabdd57 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1060,12 +1060,6 @@ def is_sorted(seq): return assert_numpy_array_equal(seq, np.sort(np.array(seq))) -def assertIs(first, second, msg=''): - """Checks that 'first' is 'second'""" - a, b = first, second - assert a is b, "%s: %r is not %r" % (msg.format(a, b), a, b) - - def assert_categorical_equal(left, right, check_dtype=True, obj='Categorical', check_category_order=True): """Test that Categoricals are equivalent.