当前位置: 首页>>代码示例>>Python>>正文


Python util.hash_pandas_object方法代码示例

本文整理汇总了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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_hashing.py

示例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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_hashing.py

示例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() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_hashing.py

示例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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_hashing.py

示例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] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_hashing.py

示例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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_hashing.py

示例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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_hashing.py

示例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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_hashing.py

示例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() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_hashing.py

示例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") 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_hashing.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:test_hashing.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_hashing.py

示例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() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_hashing.py

示例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] 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:test_hashing.py

示例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 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:test_hashing.py


注:本文中的pandas.util.hash_pandas_object方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。