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


Python testing.assert_contains_all方法代码示例

本文整理汇总了Python中pandas.util.testing.assert_contains_all方法的典型用法代码示例。如果您正苦于以下问题:Python testing.assert_contains_all方法的具体用法?Python testing.assert_contains_all怎么用?Python testing.assert_contains_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.util.testing的用法示例。


在下文中一共展示了testing.assert_contains_all方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_union_dt_as_obj

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_union_dt_as_obj(self):
        # TODO: Replace with fixturesult
        with tm.assert_produces_warning(RuntimeWarning):
            firstCat = self.strIndex.union(self.dateIndex)
        secondCat = self.strIndex.union(self.strIndex)

        if self.dateIndex.dtype == np.object_:
            appended = np.append(self.strIndex, self.dateIndex)
        else:
            appended = np.append(self.strIndex, self.dateIndex.astype('O'))

        assert tm.equalContents(firstCat, appended)
        assert tm.equalContents(secondCat, self.strIndex)
        tm.assert_contains_all(self.strIndex, firstCat)
        tm.assert_contains_all(self.strIndex, secondCat)
        tm.assert_contains_all(self.dateIndex, firstCat) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_base.py

示例2: test_constructor

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_constructor(self):
        # regular instance creation
        tm.assert_contains_all(self.strIndex, self.strIndex)
        tm.assert_contains_all(self.dateIndex, self.dateIndex)

        # casting
        arr = np.array(self.strIndex)
        index = Index(arr)
        tm.assert_contains_all(arr, index)
        tm.assert_index_equal(self.strIndex, index)

        # copy
        arr = np.array(self.strIndex)
        index = Index(arr, copy=True, name='name')
        assert isinstance(index, Index)
        assert index.name == 'name'
        tm.assert_numpy_array_equal(arr, index.values)
        arr[0] = "SOMEBIGLONGSTRING"
        assert index[0] != "SOMEBIGLONGSTRING"

        # what to do here?
        # arr = np.array(5.)
        # pytest.raises(Exception, arr.view, Index) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:25,代码来源:test_base.py

示例3: test_constructor_regular

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_constructor_regular(self, attr):
        # regular instance creation
        index = getattr(self, attr)
        tm.assert_contains_all(index, index) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_base.py

示例4: test_constructor_casting

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_constructor_casting(self):
        # casting
        arr = np.array(self.strIndex)
        index = Index(arr)
        tm.assert_contains_all(arr, index)
        tm.assert_index_equal(self.strIndex, index) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_base.py

示例5: test_union_dt_as_obj

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_union_dt_as_obj(self, sort):
        # TODO: Replace with fixturesult
        firstCat = self.strIndex.union(self.dateIndex)
        secondCat = self.strIndex.union(self.strIndex)

        if self.dateIndex.dtype == np.object_:
            appended = np.append(self.strIndex, self.dateIndex)
        else:
            appended = np.append(self.strIndex, self.dateIndex.astype('O'))

        assert tm.equalContents(firstCat, appended)
        assert tm.equalContents(secondCat, self.strIndex)
        tm.assert_contains_all(self.strIndex, firstCat)
        tm.assert_contains_all(self.strIndex, secondCat)
        tm.assert_contains_all(self.dateIndex, firstCat) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_base.py

示例6: test_reading_all_sheets

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_reading_all_sheets(self, ext):
        # Test reading all sheetnames by setting sheetname to None,
        # Ensure a dict is returned.
        # See PR #9450
        basename = 'test_multisheet'
        dfs = self.get_exceldf(basename, ext, sheet_name=None)
        # ensure this is not alphabetical to test order preservation
        expected_keys = ['Charlie', 'Alpha', 'Beta']
        tm.assert_contains_all(expected_keys, dfs.keys())
        # Issue 9930
        # Ensure sheet order is preserved
        assert expected_keys == list(dfs.keys()) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_excel.py

示例7: test_reading_multiple_specific_sheets

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_reading_multiple_specific_sheets(self, ext):
        # Test reading specific sheetnames by specifying a mixed list
        # of integers and strings, and confirm that duplicated sheet
        # references (positions/names) are removed properly.
        # Ensure a dict is returned
        # See PR #9450
        basename = 'test_multisheet'
        # Explicitly request duplicates. Only the set should be returned.
        expected_keys = [2, 'Charlie', 'Charlie']
        dfs = self.get_exceldf(basename, ext, sheet_name=expected_keys)
        expected_keys = list(set(expected_keys))
        tm.assert_contains_all(expected_keys, dfs.keys())
        assert len(expected_keys) == len(dfs.keys()) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_excel.py

示例8: test_reading_all_sheets_with_blank

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_reading_all_sheets_with_blank(self, ext):
        # Test reading all sheetnames by setting sheetname to None,
        # In the case where some sheets are blank.
        # Issue #11711
        basename = 'blank_with_header'
        dfs = self.get_exceldf(basename, ext, sheet_name=None)
        expected_keys = ['Sheet1', 'Sheet2', 'Sheet3']
        tm.assert_contains_all(expected_keys, dfs.keys())

    # GH6403 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_excel.py

示例9: test_contains

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_contains(self):
        tm.assert_contains_all(self.ts.index, self.ts) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:4,代码来源:test_api.py

示例10: test_reading_all_sheets

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_reading_all_sheets(self):
        # Test reading all sheetnames by setting sheetname to None,
        # Ensure a dict is returned.
        # See PR #9450
        basename = 'test_multisheet'
        dfs = self.get_exceldf(basename, sheet_name=None)
        # ensure this is not alphabetical to test order preservation
        expected_keys = ['Charlie', 'Alpha', 'Beta']
        tm.assert_contains_all(expected_keys, dfs.keys())
        # Issue 9930
        # Ensure sheet order is preserved
        assert expected_keys == list(dfs.keys()) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:14,代码来源:test_excel.py

示例11: test_reading_all_sheets_with_blank

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_reading_all_sheets_with_blank(self):
        # Test reading all sheetnames by setting sheetname to None,
        # In the case where some sheets are blank.
        # Issue #11711
        basename = 'blank_with_header'
        dfs = self.get_exceldf(basename, sheet_name=None)
        expected_keys = ['Sheet1', 'Sheet2', 'Sheet3']
        tm.assert_contains_all(expected_keys, dfs.keys())

    # GH6403 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:12,代码来源:test_excel.py

示例12: test_from_to_scipy

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype):
    # GH 4343
    # Make one ndarray and from it one sparse matrix, both to be used for
    # constructing frames and comparing results
    arr = np.eye(3, dtype=dtype)
    # GH 16179
    arr[0, 1] = dtype(2)
    try:
        spm = spmatrix(arr)
        assert spm.dtype == arr.dtype
    except (TypeError, AssertionError):
        # If conversion to sparse fails for this spmatrix type and arr.dtype,
        # then the combination is not currently supported in NumPy, so we
        # can just skip testing it thoroughly
        return

    sdf = SparseDataFrame(spm, index=index, columns=columns,
                          default_fill_value=fill_value)

    # Expected result construction is kind of tricky for all
    # dtype-fill_value combinations; easiest to cast to something generic
    # and except later on
    rarr = arr.astype(object)
    rarr[arr == 0] = np.nan
    expected = SparseDataFrame(rarr, index=index, columns=columns).fillna(
        fill_value if fill_value is not None else np.nan)

    # Assert frame is as expected
    sdf_obj = sdf.astype(object)
    tm.assert_sp_frame_equal(sdf_obj, expected)
    tm.assert_frame_equal(sdf_obj.to_dense(), expected.to_dense())

    # Assert spmatrices equal
    assert dict(sdf.to_coo().todok()) == dict(spm.todok())

    # Ensure dtype is preserved if possible
    # XXX: verify this
    res_dtype = bool if is_bool_dtype(dtype) else dtype
    tm.assert_contains_all(sdf.dtypes.apply(lambda dtype: dtype.subtype),
                           {np.dtype(res_dtype)})
    assert sdf.to_coo().dtype == res_dtype

    # However, adding a str column results in an upcast to object
    sdf['strings'] = np.arange(len(sdf)).astype(str)
    assert sdf.to_coo().dtype == np.object_ 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:47,代码来源:test_to_from_scipy.py

示例13: test_from_to_scipy_object

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_contains_all [as 别名]
def test_from_to_scipy_object(spmatrix, fill_value):
    # GH 4343
    dtype = object
    columns = list('cd')
    index = list('ab')

    if (spmatrix is scipy.sparse.dok_matrix and LooseVersion(
            scipy.__version__) >= LooseVersion('0.19.0')):
        pytest.skip("dok_matrix from object does not work in SciPy >= 0.19")

    # Make one ndarray and from it one sparse matrix, both to be used for
    # constructing frames and comparing results
    arr = np.eye(2, dtype=dtype)
    try:
        spm = spmatrix(arr)
        assert spm.dtype == arr.dtype
    except (TypeError, AssertionError):
        # If conversion to sparse fails for this spmatrix type and arr.dtype,
        # then the combination is not currently supported in NumPy, so we
        # can just skip testing it thoroughly
        return

    sdf = SparseDataFrame(spm, index=index, columns=columns,
                          default_fill_value=fill_value)

    # Expected result construction is kind of tricky for all
    # dtype-fill_value combinations; easiest to cast to something generic
    # and except later on
    rarr = arr.astype(object)
    rarr[arr == 0] = np.nan
    expected = SparseDataFrame(rarr, index=index, columns=columns).fillna(
        fill_value if fill_value is not None else np.nan)

    # Assert frame is as expected
    sdf_obj = sdf.astype(SparseDtype(object, fill_value))
    tm.assert_sp_frame_equal(sdf_obj, expected)
    tm.assert_frame_equal(sdf_obj.to_dense(), expected.to_dense())

    # Assert spmatrices equal
    assert dict(sdf.to_coo().todok()) == dict(spm.todok())

    # Ensure dtype is preserved if possible
    res_dtype = object
    tm.assert_contains_all(sdf.dtypes.apply(lambda dtype: dtype.subtype),
                           {np.dtype(res_dtype)})
    assert sdf.to_coo().dtype == res_dtype 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:48,代码来源:test_to_from_scipy.py


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