Python pandas.util.testing.equalContents() Examples
The following are 30
code examples of pandas.util.testing.equalContents().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.util.testing
, or try the search function
.
Example #1
Source File: test_setops.py From recruit with Apache License 2.0 | 6 votes |
def test_intersection2(self): first = tm.makeDateIndex(10) second = first[5:] intersect = first.intersection(second) assert tm.equalContents(intersect, second) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: result = first.intersection(case) assert tm.equalContents(result, second) third = Index(['a', 'b', 'c']) result = first.intersection(third) expected = pd.Index([], dtype=object) tm.assert_index_equal(result, expected)
Example #2
Source File: test_base.py From recruit with Apache License 2.0 | 6 votes |
def test_difference_name_preservation(self, second_name, expected, sort): # TODO: replace with fixturesult first = self.strIndex[5:20] second = self.strIndex[:10] answer = self.strIndex[10:20] first.name = 'name' second.name = second_name result = first.difference(second, sort=sort) assert tm.equalContents(result, answer) if expected is None: assert result.name is None else: assert result.name == expected
Example #3
Source File: test_base.py From recruit with Apache License 2.0 | 6 votes |
def test_symmetric_difference(self, sort): # smoke index1 = Index([5, 2, 3, 4], name='index1') index2 = Index([2, 3, 4, 1]) result = index1.symmetric_difference(index2, sort=sort) expected = Index([5, 1]) assert tm.equalContents(result, expected) assert result.name is None if sort is None: expected = expected.sort_values() tm.assert_index_equal(result, expected) # __xor__ syntax expected = index1 ^ index2 assert tm.equalContents(result, expected) assert result.name is None
Example #4
Source File: test_setops.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_intersection2(self): first = tm.makeDateIndex(10) second = first[5:] intersect = first.intersection(second) assert tm.equalContents(intersect, second) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: result = first.intersection(case) assert tm.equalContents(result, second) third = Index(['a', 'b', 'c']) result = first.intersection(third) expected = pd.Index([], dtype=object) tm.assert_index_equal(result, expected)
Example #5
Source File: test_interval.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_symmetric_difference(self, closed, sort): index = self.create_index(closed=closed) result = index[1:].symmetric_difference(index[:-1], sort=sort) expected = IntervalIndex([index[0], index[-1]]) if sort is None: tm.assert_index_equal(result, expected) assert tm.equalContents(result, expected) # GH 19101: empty result, same dtype result = index.symmetric_difference(index, sort=sort) expected = IntervalIndex(np.array([], dtype='int64'), closed=closed) if sort is None: tm.assert_index_equal(result, expected) assert tm.equalContents(result, expected) # GH 19101: empty result, different dtypes other = IntervalIndex.from_arrays(index.left.astype('float64'), index.right, closed=closed) result = index.symmetric_difference(other, sort=sort) tm.assert_index_equal(result, expected)
Example #6
Source File: test_base.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_symmetric_difference(self, sort): # smoke index1 = Index([5, 2, 3, 4], name='index1') index2 = Index([2, 3, 4, 1]) result = index1.symmetric_difference(index2, sort=sort) expected = Index([5, 1]) assert tm.equalContents(result, expected) assert result.name is None if sort is None: expected = expected.sort_values() tm.assert_index_equal(result, expected) # __xor__ syntax expected = index1 ^ index2 assert tm.equalContents(result, expected) assert result.name is None
Example #7
Source File: test_base.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_difference_name_preservation(self, second_name, expected, sort): # TODO: replace with fixturesult first = self.strIndex[5:20] second = self.strIndex[:10] answer = self.strIndex[10:20] first.name = 'name' second.name = second_name result = first.difference(second, sort=sort) assert tm.equalContents(result, answer) if expected is None: assert result.name is None else: assert result.name == expected
Example #8
Source File: test_interval.py From recruit with Apache License 2.0 | 6 votes |
def test_symmetric_difference(self, closed, sort): index = self.create_index(closed=closed) result = index[1:].symmetric_difference(index[:-1], sort=sort) expected = IntervalIndex([index[0], index[-1]]) if sort is None: tm.assert_index_equal(result, expected) assert tm.equalContents(result, expected) # GH 19101: empty result, same dtype result = index.symmetric_difference(index, sort=sort) expected = IntervalIndex(np.array([], dtype='int64'), closed=closed) if sort is None: tm.assert_index_equal(result, expected) assert tm.equalContents(result, expected) # GH 19101: empty result, different dtypes other = IntervalIndex.from_arrays(index.left.astype('float64'), index.right, closed=closed) result = index.symmetric_difference(other, sort=sort) tm.assert_index_equal(result, expected)
Example #9
Source File: test_setops.py From recruit with Apache License 2.0 | 6 votes |
def test_intersection(self, sort): index = period_range('1/1/2000', '1/20/2000', freq='D') result = index[:-5].intersection(index[10:], sort=sort) tm.assert_index_equal(result, index[10:-5]) # not in order left = _permute(index[:-5]) right = _permute(index[10:]) result = left.intersection(right, sort=sort) if sort is None: tm.assert_index_equal(result, index[10:-5]) assert tm.equalContents(result, index[10:-5]) # raise if different frequencies index = period_range('1/1/2000', '1/20/2000', freq='D') index2 = period_range('1/1/2000', '1/20/2000', freq='W-WED') with pytest.raises(period.IncompatibleFrequency): index.intersection(index2, sort=sort) index3 = period_range('1/1/2000', '1/20/2000', freq='2D') with pytest.raises(period.IncompatibleFrequency): index.intersection(index3, sort=sort)
Example #10
Source File: test_set_ops.py From recruit with Apache License 2.0 | 6 votes |
def test_intersection_base(idx, sort): first = idx[:5] second = idx[:3] intersect = first.intersection(second, sort=sort) if sort is None: tm.assert_index_equal(intersect, second.sort_values()) assert tm.equalContents(intersect, second) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: result = first.intersection(case, sort=sort) if sort is None: tm.assert_index_equal(result, second.sort_values()) assert tm.equalContents(result, second) msg = "other must be a MultiIndex or a list of tuples" with pytest.raises(TypeError, match=msg): first.intersection([1, 2, 3], sort=sort)
Example #11
Source File: test_set_ops.py From recruit with Apache License 2.0 | 6 votes |
def test_union_base(idx, sort): first = idx[3:] second = idx[:5] everything = idx union = first.union(second, sort=sort) if sort is None: tm.assert_index_equal(union, everything.sort_values()) assert tm.equalContents(union, everything) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: result = first.union(case, sort=sort) if sort is None: tm.assert_index_equal(result, everything.sort_values()) assert tm.equalContents(result, everything) msg = "other must be a MultiIndex or a list of tuples" with pytest.raises(TypeError, match=msg): first.union([1, 2, 3], sort=sort)
Example #12
Source File: test_set_ops.py From recruit with Apache License 2.0 | 6 votes |
def test_intersection(idx, sort): piece1 = idx[:5][::-1] piece2 = idx[3:] the_int = piece1.intersection(piece2, sort=sort) if sort is None: tm.assert_index_equal(the_int, idx[3:5]) assert tm.equalContents(the_int, idx[3:5]) # corner case, pass self the_int = idx.intersection(idx, sort=sort) assert the_int is idx # empty intersection: disjoint empty = idx[:2].intersection(idx[2:], sort=sort) expected = idx[:0] assert empty.equals(expected) # can't do in python 3 # tuples = _index.values # result = _index & tuples # assert result.equals(tuples)
Example #13
Source File: test_timeseries.py From Computable with MIT License | 6 votes |
def test_timedelta(self): # this is valid too index = date_range('1/1/2000', periods=50, freq='B') shifted = index + timedelta(1) back = shifted + timedelta(-1) self.assert_(tm.equalContents(index, back)) self.assertEqual(shifted.freq, index.freq) self.assertEqual(shifted.freq, back.freq) result = index - timedelta(1) expected = index + timedelta(-1) self.assert_(result.equals(expected)) # GH4134, buggy with timedeltas rng = date_range('2013', '2014') s = Series(rng) result1 = rng - pd.offsets.Hour(1) result2 = DatetimeIndex(s - np.timedelta64(100000000)) result3 = rng - np.timedelta64(100000000) result4 = DatetimeIndex(s - pd.offsets.Hour(1)) self.assert_(result1.equals(result4)) self.assert_(result2.equals(result3))
Example #14
Source File: test_indexing.py From vnpy_crypto with MIT License | 6 votes |
def test_slice(test_data): numSlice = test_data.series[10:20] numSliceEnd = test_data.series[-10:] objSlice = test_data.objSeries[10:20] assert test_data.series.index[9] not in numSlice.index assert test_data.objSeries.index[9] not in objSlice.index assert len(numSlice) == len(numSlice.index) assert test_data.series[numSlice.index[0]] == numSlice[numSlice.index[0]] assert numSlice.index[1] == test_data.series.index[11] assert tm.equalContents(numSliceEnd, np.array(test_data.series)[-10:]) # Test return view. sl = test_data.series[10:20] sl[:] = 0 assert (test_data.series[10:20] == 0).all()
Example #15
Source File: test_setops.py From vnpy_crypto with MIT License | 6 votes |
def test_intersection2(self): first = tm.makeDateIndex(10) second = first[5:] intersect = first.intersection(second) assert tm.equalContents(intersect, second) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: result = first.intersection(case) assert tm.equalContents(result, second) third = Index(['a', 'b', 'c']) result = first.intersection(third) expected = pd.Index([], dtype=object) tm.assert_index_equal(result, expected)
Example #16
Source File: test_base.py From vnpy_crypto with MIT License | 6 votes |
def test_difference_name_preservation(self, second_name, expected): # TODO: replace with fixturesult first = self.strIndex[5:20] second = self.strIndex[:10] answer = self.strIndex[10:20] first.name = 'name' second.name = second_name result = first.difference(second) assert tm.equalContents(result, answer) if expected is None: assert result.name is None else: assert result.name == expected
Example #17
Source File: common.py From vnpy_crypto with MIT License | 5 votes |
def test_symmetric_difference(self): for name, idx in compat.iteritems(self.indices): first = idx[1:] second = idx[:-1] if isinstance(idx, CategoricalIndex): pass else: answer = idx[[0, -1]] result = first.symmetric_difference(second) assert tm.equalContents(result, answer) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: if isinstance(idx, PeriodIndex): msg = "can only call with other PeriodIndex-ed objects" with tm.assert_raises_regex(ValueError, msg): result = first.symmetric_difference(case) elif isinstance(idx, CategoricalIndex): pass else: result = first.symmetric_difference(case) assert tm.equalContents(result, answer) if isinstance(idx, MultiIndex): msg = "other must be a MultiIndex or a list of tuples" with tm.assert_raises_regex(TypeError, msg): first.symmetric_difference([1, 2, 3])
Example #18
Source File: test_base.py From vnpy_crypto with MIT License | 5 votes |
def test_difference_empty_arg(self): first = self.strIndex[5:20] first.name == 'name' result = first.difference([]) assert tm.equalContents(result, first) assert result.name == first.name
Example #19
Source File: test_panel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_iter(self): tm.equalContents(list(self.panel), self.panel.items)
Example #20
Source File: common.py From vnpy_crypto with MIT License | 5 votes |
def test_union_base(self): for name, idx in compat.iteritems(self.indices): first = idx[3:] second = idx[:5] everything = idx union = first.union(second) assert tm.equalContents(union, everything) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: if isinstance(idx, PeriodIndex): msg = "can only call with other PeriodIndex-ed objects" with tm.assert_raises_regex(ValueError, msg): result = first.union(case) elif isinstance(idx, CategoricalIndex): pass else: result = first.union(case) assert tm.equalContents(result, everything) if isinstance(idx, MultiIndex): msg = "other must be a MultiIndex or a list of tuples" with tm.assert_raises_regex(TypeError, msg): result = first.union([1, 2, 3])
Example #21
Source File: common.py From vnpy_crypto with MIT License | 5 votes |
def test_intersection_base(self): for name, idx in compat.iteritems(self.indices): first = idx[:5] second = idx[:3] intersect = first.intersection(second) if isinstance(idx, CategoricalIndex): pass else: assert tm.equalContents(intersect, second) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: if isinstance(idx, PeriodIndex): msg = "can only call with other PeriodIndex-ed objects" with tm.assert_raises_regex(ValueError, msg): result = first.intersection(case) elif isinstance(idx, CategoricalIndex): pass else: result = first.intersection(case) assert tm.equalContents(result, second) if isinstance(idx, MultiIndex): msg = "other must be a MultiIndex or a list of tuples" with tm.assert_raises_regex(TypeError, msg): result = first.intersection([1, 2, 3])
Example #22
Source File: test_base.py From vnpy_crypto with MIT License | 5 votes |
def test_intersection_different_type_base(self, klass): # GH 10149 index = self.create_index() first = index[:5] second = index[:3] result = first.intersection(klass(second.values)) assert tm.equalContents(result, second)
Example #23
Source File: common.py From vnpy_crypto with MIT License | 5 votes |
def test_difference_base(self): for name, idx in compat.iteritems(self.indices): first = idx[2:] second = idx[:4] answer = idx[4:] result = first.difference(second) if isinstance(idx, CategoricalIndex): pass else: assert tm.equalContents(result, answer) # GH 10149 cases = [klass(second.values) for klass in [np.array, Series, list]] for case in cases: if isinstance(idx, PeriodIndex): msg = "can only call with other PeriodIndex-ed objects" with tm.assert_raises_regex(ValueError, msg): result = first.difference(case) elif isinstance(idx, CategoricalIndex): pass elif isinstance(idx, (DatetimeIndex, TimedeltaIndex)): assert result.__class__ == answer.__class__ tm.assert_numpy_array_equal(result.sort_values().asi8, answer.sort_values().asi8) else: result = first.difference(case) assert tm.equalContents(result, answer) if isinstance(idx, MultiIndex): msg = "other must be a MultiIndex or a list of tuples" with tm.assert_raises_regex(TypeError, msg): result = first.difference([1, 2, 3])
Example #24
Source File: test_interval.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_union(self, closed, sort): index = self.create_index(closed=closed) other = IntervalIndex.from_breaks(range(5, 13), closed=closed) expected = IntervalIndex.from_breaks(range(13), closed=closed) result = index[::-1].union(other, sort=sort) if sort is None: tm.assert_index_equal(result, expected) assert tm.equalContents(result, expected) result = other[::-1].union(index, sort=sort) if sort is None: tm.assert_index_equal(result, expected) assert tm.equalContents(result, expected) tm.assert_index_equal(index.union(index, sort=sort), index) tm.assert_index_equal(index.union(index[:1], sort=sort), index) # GH 19101: empty result, same dtype index = IntervalIndex(np.array([], dtype='int64'), closed=closed) result = index.union(index, sort=sort) tm.assert_index_equal(result, index) # GH 19101: empty result, different dtypes other = IntervalIndex(np.array([], dtype='float64'), closed=closed) result = index.union(other, sort=sort) tm.assert_index_equal(result, index)
Example #25
Source File: test_operators.py From vnpy_crypto with MIT License | 5 votes |
def test_ne(self): ts = Series([3, 4, 5, 6, 7], [3, 4, 5, 6, 7], dtype=float) expected = [True, True, False, True, True] assert tm.equalContents(ts.index != 5, expected) assert tm.equalContents(~(ts.index == 5), expected)
Example #26
Source File: test_constructors.py From vnpy_crypto with MIT License | 5 votes |
def test_constructor(self): assert self.ts.index.is_all_dates # Pass in Series derived = Series(self.ts) assert derived.index.is_all_dates assert tm.equalContents(derived.index, self.ts.index) # Ensure new index is not created assert id(self.ts.index) == id(derived.index) # Mixed type Series mixed = Series(['hello', np.NaN], index=[0, 1]) assert mixed.dtype == np.object_ assert mixed[1] is np.NaN assert not self.empty.index.is_all_dates assert not Series({}).index.is_all_dates pytest.raises(Exception, Series, np.random.randn(3, 3), index=np.arange(3)) mixed.name = 'Series' rs = Series(mixed).name xp = 'Series' assert rs == xp # raise on MultiIndex GH4187 m = MultiIndex.from_arrays([[1, 2], [3, 4]]) pytest.raises(NotImplementedError, Series, m)
Example #27
Source File: test_api.py From vnpy_crypto with MIT License | 5 votes |
def test_iter(self): assert tm.equalContents(list(self.frame), self.frame.columns)
Example #28
Source File: test_sql.py From vnpy_crypto with MIT License | 5 votes |
def _check_iris_loaded_frame(self, iris_frame): pytype = iris_frame.dtypes[0].type row = iris_frame.iloc[0] assert issubclass(pytype, np.floating) tm.equalContents(row.values, [5.1, 3.5, 1.4, 0.2, 'Iris-setosa'])
Example #29
Source File: test_sql.py From vnpy_crypto with MIT License | 5 votes |
def _execute_sql(self): # drop_sql = "DROP TABLE IF EXISTS test" # should already be done iris_results = self.pandasSQL.execute("SELECT * FROM iris") row = iris_results.fetchone() tm.equalContents(row, [5.1, 3.5, 1.4, 0.2, 'Iris-setosa'])
Example #30
Source File: test_interval.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_intersection(self, closed, sort): index = self.create_index(closed=closed) other = IntervalIndex.from_breaks(range(5, 13), closed=closed) expected = IntervalIndex.from_breaks(range(5, 11), closed=closed) result = index[::-1].intersection(other, sort=sort) if sort is None: tm.assert_index_equal(result, expected) assert tm.equalContents(result, expected) result = other[::-1].intersection(index, sort=sort) if sort is None: tm.assert_index_equal(result, expected) assert tm.equalContents(result, expected) tm.assert_index_equal(index.intersection(index, sort=sort), index) # GH 19101: empty result, same dtype other = IntervalIndex.from_breaks(range(300, 314), closed=closed) expected = IntervalIndex(np.array([], dtype='int64'), closed=closed) result = index.intersection(other, sort=sort) tm.assert_index_equal(result, expected) # GH 19101: empty result, different dtypes breaks = np.arange(300, 314, dtype='float64') other = IntervalIndex.from_breaks(breaks, closed=closed) result = index.intersection(other, sort=sort) tm.assert_index_equal(result, expected)