當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。