本文整理汇总了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='~~')
示例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='~~')