diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index ef5f13bfa504a..61f838eeeeb30 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -25,7 +25,6 @@ def test_mut_exclusive(): def test_get_callable_name(): - from functools import partial getname = com._get_callable_name def fn(x): @@ -154,8 +153,7 @@ def test_random_state(): # Check with random state object state2 = npr.RandomState(10) - assert (com._random_state(state2).uniform() == - npr.RandomState(10).uniform()) + assert com._random_state(state2).uniform() == npr.RandomState(10).uniform() # check with no arg random state assert com._random_state() is np.random @@ -168,29 +166,15 @@ def test_random_state(): com._random_state(5.5) -def test_maybe_match_name(): - - matched = ops._maybe_match_name( - Series([1], name='x'), Series( - [2], name='x')) - assert (matched == 'x') - - matched = ops._maybe_match_name( - Series([1], name='x'), Series( - [2], name='y')) - assert (matched is None) - - matched = ops._maybe_match_name(Series([1]), Series([2], name='x')) - assert (matched is None) - - matched = ops._maybe_match_name(Series([1], name='x'), Series([2])) - assert (matched is None) - - matched = ops._maybe_match_name(Series([1], name='x'), [2]) - assert (matched == 'x') - - matched = ops._maybe_match_name([1], Series([2], name='y')) - assert (matched == 'y') +@pytest.mark.parametrize('left, right, expected', [ + (Series([1], name='x'), Series([2], name='x'), 'x'), + (Series([1], name='x'), Series([2], name='y'), None), + (Series([1]), Series([2], name='x'), None), + (Series([1], name='x'), Series([2]), None), + (Series([1], name='x'), [2], 'x'), + ([1], Series([2], name='y'), 'y')]) +def test_maybe_match_name(left, right, expected): + assert ops._maybe_match_name(left, right) == expected def test_dict_compat(): diff --git a/pandas/tests/util/test_hashing.py b/pandas/tests/util/test_hashing.py index fe8d75539879e..82b870c156cc8 100644 --- a/pandas/tests/util/test_hashing.py +++ b/pandas/tests/util/test_hashing.py @@ -142,39 +142,35 @@ def test_multiindex_objects(self): tm.assert_numpy_array_equal(np.sort(result), np.sort(expected)) - def test_hash_pandas_object(self): - - for obj in [Series([1, 2, 3]), - Series([1.0, 1.5, 3.2]), - Series([1.0, 1.5, np.nan]), - Series([1.0, 1.5, 3.2], index=[1.5, 1.1, 3.3]), - Series(['a', 'b', 'c']), - Series(['a', np.nan, 'c']), - Series(['a', None, 'c']), - Series([True, False, True]), - Series(), - Index([1, 2, 3]), - Index([True, False, True]), - DataFrame({'x': ['a', 'b', 'c'], 'y': [1, 2, 3]}), - DataFrame(), - tm.makeMissingDataframe(), - tm.makeMixedDataFrame(), - tm.makeTimeDataFrame(), - tm.makeTimeSeries(), - tm.makeTimedeltaIndex(), - tm.makePeriodIndex(), - Series(tm.makePeriodIndex()), - Series(pd.date_range('20130101', - periods=3, tz='US/Eastern')), - MultiIndex.from_product( - [range(5), - ['foo', 'bar', 'baz'], - pd.date_range('20130101', periods=2)]), - MultiIndex.from_product( - [pd.CategoricalIndex(list('aabc')), - range(3)])]: - self.check_equal(obj) - self.check_not_equal_with_index(obj) + @pytest.mark.parametrize('obj', [ + Series([1, 2, 3]), + Series([1.0, 1.5, 3.2]), + Series([1.0, 1.5, np.nan]), + Series([1.0, 1.5, 3.2], index=[1.5, 1.1, 3.3]), + Series(['a', 'b', 'c']), + Series(['a', np.nan, 'c']), + Series(['a', None, 'c']), + Series([True, False, True]), + Series(), + Index([1, 2, 3]), + Index([True, False, True]), + DataFrame({'x': ['a', 'b', 'c'], 'y': [1, 2, 3]}), + DataFrame(), + tm.makeMissingDataframe(), + tm.makeMixedDataFrame(), + tm.makeTimeDataFrame(), + tm.makeTimeSeries(), + tm.makeTimedeltaIndex(), + tm.makePeriodIndex(), + Series(tm.makePeriodIndex()), + Series(pd.date_range('20130101', periods=3, tz='US/Eastern')), + MultiIndex.from_product([range(5), ['foo', 'bar', 'baz'], + pd.date_range('20130101', periods=2)]), + MultiIndex.from_product([pd.CategoricalIndex(list('aabc')), range(3)]) + ]) + def test_hash_pandas_object(self, obj): + self.check_equal(obj) + self.check_not_equal_with_index(obj) def test_hash_pandas_object2(self): for name, s in self.df.iteritems():