本文整理汇总了Python中pandas.util.hash_pandas_object方法的典型用法代码示例。如果您正苦于以下问题:Python util.hash_pandas_object方法的具体用法?Python util.hash_pandas_object怎么用?Python util.hash_pandas_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.util
的用法示例。
在下文中一共展示了util.hash_pandas_object方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_categorical_consistency
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_categorical_consistency(self):
# GH15143
# Check that categoricals hash consistent with their values, not codes
# This should work for categoricals of any dtype
for s1 in [Series(['a', 'b', 'c', 'd']),
Series([1000, 2000, 3000, 4000]),
Series(pd.date_range(0, periods=4))]:
s2 = s1.astype('category').cat.set_categories(s1)
s3 = s2.cat.set_categories(list(reversed(s1)))
for categorize in [True, False]:
# These should all hash identically
h1 = hash_pandas_object(s1, categorize=categorize)
h2 = hash_pandas_object(s2, categorize=categorize)
h3 = hash_pandas_object(s3, categorize=categorize)
tm.assert_series_equal(h1, h2)
tm.assert_series_equal(h1, h3)
示例2: _check_equal
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def _check_equal(obj, **kwargs):
"""
Check that hashing an objects produces the same value each time.
Parameters
----------
obj : object
The object to hash.
kwargs : kwargs
Keyword arguments to pass to the hashing function.
"""
a = hash_pandas_object(obj, **kwargs)
b = hash_pandas_object(obj, **kwargs)
tm.assert_series_equal(a, b)
示例3: _check_not_equal_with_index
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def _check_not_equal_with_index(obj):
"""
Check the hash of an object with and without its index is not the same.
Parameters
----------
obj : object
The object to hash.
"""
if not isinstance(obj, Index):
a = hash_pandas_object(obj, index=True)
b = hash_pandas_object(obj, index=False)
if len(obj):
assert not (a == b).all()
示例4: test_consistency
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_consistency():
# Check that our hash doesn't change because of a mistake
# in the actual code; this is the ground truth.
result = hash_pandas_object(Index(["foo", "bar", "baz"]))
expected = Series(np.array([3600424527151052760, 1374399572096150070,
477881037637427054], dtype="uint64"),
index=["foo", "bar", "baz"])
tm.assert_series_equal(result, expected)
示例5: test_hash_tuples
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_hash_tuples():
tuples = [(1, "one"), (1, "two"), (2, "one")]
result = hash_tuples(tuples)
expected = hash_pandas_object(MultiIndex.from_tuples(tuples)).values
tm.assert_numpy_array_equal(result, expected)
result = hash_tuples(tuples[0])
assert result == expected[0]
示例6: test_multiindex_unique
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_multiindex_unique():
mi = MultiIndex.from_tuples([(118, 472), (236, 118),
(51, 204), (102, 51)])
assert mi.is_unique is True
result = hash_pandas_object(mi)
assert result.is_unique is True
示例7: test_categorical_consistency
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_categorical_consistency(s1, categorize):
# see gh-15143
#
# Check that categoricals hash consistent with their values,
# not codes. This should work for categoricals of any dtype.
s2 = s1.astype("category").cat.set_categories(s1)
s3 = s2.cat.set_categories(list(reversed(s1)))
# These should all hash identically.
h1 = hash_pandas_object(s1, categorize=categorize)
h2 = hash_pandas_object(s2, categorize=categorize)
h3 = hash_pandas_object(s3, categorize=categorize)
tm.assert_series_equal(h1, h2)
tm.assert_series_equal(h1, h3)
示例8: test_pandas_errors
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_pandas_errors(obj):
msg = "Unexpected type for hashing"
with pytest.raises(TypeError, match=msg):
hash_pandas_object(obj)
示例9: test_hash_keys
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_hash_keys():
# Using different hash keys, should have
# different hashes for the same data.
#
# This only matters for object dtypes.
obj = Series(list("abc"))
a = hash_pandas_object(obj, hash_key="9876543210123456")
b = hash_pandas_object(obj, hash_key="9876543210123465")
assert (a != b).all()
示例10: test_invalid_key
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_invalid_key():
# This only matters for object dtypes.
msg = "key should be a 16-byte string encoded"
with pytest.raises(ValueError, match=msg):
hash_pandas_object(Series(list("abc")), hash_key="foo")
示例11: test_consistency
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_consistency(self):
# check that our hash doesn't change because of a mistake
# in the actual code; this is the ground truth
result = hash_pandas_object(Index(['foo', 'bar', 'baz']))
expected = Series(np.array([3600424527151052760, 1374399572096150070,
477881037637427054], dtype='uint64'),
index=['foo', 'bar', 'baz'])
tm.assert_series_equal(result, expected)
示例12: check_equal
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def check_equal(self, obj, **kwargs):
a = hash_pandas_object(obj, **kwargs)
b = hash_pandas_object(obj, **kwargs)
tm.assert_series_equal(a, b)
kwargs.pop('index', None)
a = hash_pandas_object(obj, **kwargs)
b = hash_pandas_object(obj, **kwargs)
tm.assert_series_equal(a, b)
示例13: check_not_equal_with_index
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def check_not_equal_with_index(self, obj):
# check that we are not hashing the same if
# we include the index
if not isinstance(obj, Index):
a = hash_pandas_object(obj, index=True)
b = hash_pandas_object(obj, index=False)
if len(obj):
assert not (a == b).all()
示例14: test_hash_tuples
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_hash_tuples(self):
tups = [(1, 'one'), (1, 'two'), (2, 'one')]
result = hash_tuples(tups)
expected = hash_pandas_object(MultiIndex.from_tuples(tups)).values
tm.assert_numpy_array_equal(result, expected)
result = hash_tuples(tups[0])
assert result == expected[0]
示例15: test_multiindex_unique
# 需要导入模块: from pandas import util [as 别名]
# 或者: from pandas.util import hash_pandas_object [as 别名]
def test_multiindex_unique(self):
mi = MultiIndex.from_tuples([(118, 472), (236, 118),
(51, 204), (102, 51)])
assert mi.is_unique
result = hash_pandas_object(mi)
assert result.is_unique