當前位置: 首頁>>代碼示例>>Python>>正文


Python parsers.ParserWarning方法代碼示例

本文整理匯總了Python中pandas.io.parsers.ParserWarning方法的典型用法代碼示例。如果您正苦於以下問題:Python parsers.ParserWarning方法的具體用法?Python parsers.ParserWarning怎麽用?Python parsers.ParserWarning使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.io.parsers的用法示例。


在下文中一共展示了parsers.ParserWarning方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_c_engine

# 需要導入模塊: from pandas.io import parsers [as 別名]
# 或者: from pandas.io.parsers import ParserWarning [as 別名]
def test_c_engine(self):
        # see gh-6607
        data = 'a b c\n1 2 3'
        msg = 'does not support'

        # specify C engine with unsupported options (raise)
        with pytest.raises(ValueError, match=msg):
            read_csv(StringIO(data), engine='c',
                     sep=None, delim_whitespace=False)
        with pytest.raises(ValueError, match=msg):
            read_csv(StringIO(data), engine='c', sep=r'\s')
        with pytest.raises(ValueError, match=msg):
            read_csv(StringIO(data), engine='c', sep='\t', quotechar=chr(128))
        with pytest.raises(ValueError, match=msg):
            read_csv(StringIO(data), engine='c', skipfooter=1)

        # specify C-unsupported options without python-unsupported options
        with tm.assert_produces_warning(parsers.ParserWarning):
            read_csv(StringIO(data), sep=None, delim_whitespace=False)
        with tm.assert_produces_warning(parsers.ParserWarning):
            read_csv(StringIO(data), sep=r'\s')
        with tm.assert_produces_warning(parsers.ParserWarning):
            read_csv(StringIO(data), sep='\t', quotechar=chr(128))
        with tm.assert_produces_warning(parsers.ParserWarning):
            read_csv(StringIO(data), skipfooter=1)

        text = """                      A       B       C       D        E
one two three   four
a   b   10.0032 5    -0.5109 -2.3358 -0.4645  0.05076  0.3640
a   q   20      4     0.4473  1.4152  0.2834  1.00661  0.1744
x   q   30      3    -0.6662 -0.5243 -0.3580  0.89145  2.5838"""
        msg = 'Error tokenizing data'

        with pytest.raises(ParserError, match=msg):
            read_csv(StringIO(text), sep='\\s+')
        with pytest.raises(ParserError, match=msg):
            read_csv(StringIO(text), engine='c', sep='\\s+')

        msg = "Only length-1 thousands markers supported"
        data = """A|B|C
1|2,334|5
10|13|10.
"""
        with pytest.raises(ValueError, match=msg):
            read_csv(StringIO(data), thousands=',,')
        with pytest.raises(ValueError, match=msg):
            read_csv(StringIO(data), thousands='')

        msg = "Only length-1 line terminators supported"
        data = 'a,b,c~~1,2,3~~4,5,6'
        with pytest.raises(ValueError, match=msg):
            read_csv(StringIO(data), lineterminator='~~') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:54,代碼來源:test_unsupported.py

示例2: test_c_engine

# 需要導入模塊: from pandas.io import parsers [as 別名]
# 或者: from pandas.io.parsers import ParserWarning [as 別名]
def test_c_engine(self):
        # see gh-6607
        data = 'a b c\n1 2 3'
        msg = 'does not support'

        # specify C engine with unsupported options (raise)
        with tm.assert_raises_regex(ValueError, msg):
            read_table(StringIO(data), engine='c',
                       sep=None, delim_whitespace=False)
        with tm.assert_raises_regex(ValueError, msg):
            read_table(StringIO(data), engine='c', sep=r'\s')
        with tm.assert_raises_regex(ValueError, msg):
            read_table(StringIO(data), engine='c', quotechar=chr(128))
        with tm.assert_raises_regex(ValueError, msg):
            read_table(StringIO(data), engine='c', skipfooter=1)

        # specify C-unsupported options without python-unsupported options
        with tm.assert_produces_warning(parsers.ParserWarning):
            read_table(StringIO(data), sep=None, delim_whitespace=False)
        with tm.assert_produces_warning(parsers.ParserWarning):
            read_table(StringIO(data), quotechar=chr(128))
        with tm.assert_produces_warning(parsers.ParserWarning):
            read_table(StringIO(data), sep=r'\s')
        with tm.assert_produces_warning(parsers.ParserWarning):
            read_table(StringIO(data), skipfooter=1)

        text = """                      A       B       C       D        E
one two three   four
a   b   10.0032 5    -0.5109 -2.3358 -0.4645  0.05076  0.3640
a   q   20      4     0.4473  1.4152  0.2834  1.00661  0.1744
x   q   30      3    -0.6662 -0.5243 -0.3580  0.89145  2.5838"""
        msg = 'Error tokenizing data'

        with tm.assert_raises_regex(ParserError, msg):
            read_table(StringIO(text), sep='\\s+')
        with tm.assert_raises_regex(ParserError, msg):
            read_table(StringIO(text), engine='c', sep='\\s+')

        msg = "Only length-1 thousands markers supported"
        data = """A|B|C
1|2,334|5
10|13|10.
"""
        with tm.assert_raises_regex(ValueError, msg):
            read_csv(StringIO(data), thousands=',,')
        with tm.assert_raises_regex(ValueError, msg):
            read_csv(StringIO(data), thousands='')

        msg = "Only length-1 line terminators supported"
        data = 'a,b,c~~1,2,3~~4,5,6'
        with tm.assert_raises_regex(ValueError, msg):
            read_csv(StringIO(data), lineterminator='~~') 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:54,代碼來源:test_unsupported.py


注:本文中的pandas.io.parsers.ParserWarning方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。