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


Python parsers.TextReader类代码示例

本文整理汇总了Python中pandas._libs.parsers.TextReader的典型用法代码示例。如果您正苦于以下问题:Python TextReader类的具体用法?Python TextReader怎么用?Python TextReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_parse_booleans

    def test_parse_booleans(self):
        data = 'True\nFalse\nTrue\nTrue'

        reader = TextReader(StringIO(data), header=None)
        result = reader.read()

        assert result[0].dtype == np.bool_
开发者ID:forking-repos,项目名称:pandas,代码行数:7,代码来源:test_textreader.py

示例2: test_file_handle_mmap

 def test_file_handle_mmap(self):
     try:
         f = open(self.csv1, 'rb')
         reader = TextReader(f, memory_map=True, header=None)
         reader.read()
     finally:
         f.close()
开发者ID:AllenDowney,项目名称:pandas,代码行数:7,代码来源:test_textreader.py

示例3: test_file_handle

 def test_file_handle(self):
     try:
         f = open(self.csv1, 'rb')
         reader = TextReader(f)
         result = reader.read()  # noqa
     finally:
         f.close()
开发者ID:AllenDowney,项目名称:pandas,代码行数:7,代码来源:test_textreader.py

示例4: test_embedded_newline

    def test_embedded_newline(self):
        data = 'a\n"hello\nthere"\nthis'

        reader = TextReader(StringIO(data), header=None)
        result = reader.read()

        expected = np.array(['a', 'hello\nthere', 'this'], dtype=np.object_)
        tm.assert_numpy_array_equal(result[0], expected)
开发者ID:forking-repos,项目名称:pandas,代码行数:8,代码来源:test_textreader.py

示例5: test_integer_thousands

    def test_integer_thousands(self):
        data = '123,456\n12,500'

        reader = TextReader(StringIO(data), delimiter=':',
                            thousands=',', header=None)
        result = reader.read()

        expected = np.array([123456, 12500], dtype=np.int64)
        tm.assert_almost_equal(result[0], expected)
开发者ID:forking-repos,项目名称:pandas,代码行数:9,代码来源:test_textreader.py

示例6: test_euro_decimal

    def test_euro_decimal(self):
        data = '12345,67\n345,678'

        reader = TextReader(StringIO(data), delimiter=':',
                            decimal=',', header=None)
        result = reader.read()

        expected = np.array([12345.67, 345.678])
        tm.assert_almost_equal(result[0], expected)
开发者ID:forking-repos,项目名称:pandas,代码行数:9,代码来源:test_textreader.py

示例7: test_escapechar

    def test_escapechar(self):
        data = ('\\"hello world\"\n'
                '\\"hello world\"\n'
                '\\"hello world\"')

        reader = TextReader(StringIO(data), delimiter=',', header=None,
                            escapechar='\\')
        result = reader.read()
        expected = {0: np.array(['"hello world"'] * 3, dtype=object)}
        assert_array_dicts_equal(result, expected)
开发者ID:forking-repos,项目名称:pandas,代码行数:10,代码来源:test_textreader.py

示例8: test_delimit_whitespace

    def test_delimit_whitespace(self):
        data = 'a  b\na\t\t "b"\n"a"\t \t b'

        reader = TextReader(StringIO(data), delim_whitespace=True,
                            header=None)
        result = reader.read()

        tm.assert_numpy_array_equal(result[0], np.array(['a', 'a', 'a'],
                                                        dtype=np.object_))
        tm.assert_numpy_array_equal(result[1], np.array(['b', 'b', 'b'],
                                                        dtype=np.object_))
开发者ID:forking-repos,项目名称:pandas,代码行数:11,代码来源:test_textreader.py

示例9: test_skip_bad_lines

    def test_skip_bad_lines(self, capsys):
        # too many lines, see #2430 for why
        data = ('a:b:c\n'
                'd:e:f\n'
                'g:h:i\n'
                'j:k:l:m\n'
                'l:m:n\n'
                'o:p:q:r')

        reader = TextReader(StringIO(data), delimiter=':',
                            header=None)
        msg = (r"Error tokenizing data\. C error: Expected 3 fields in"
               " line 4, saw 4")
        with pytest.raises(parser.ParserError, match=msg):
            reader.read()

        reader = TextReader(StringIO(data), delimiter=':',
                            header=None,
                            error_bad_lines=False,
                            warn_bad_lines=False)
        result = reader.read()
        expected = {0: np.array(['a', 'd', 'g', 'l'], dtype=object),
                    1: np.array(['b', 'e', 'h', 'm'], dtype=object),
                    2: np.array(['c', 'f', 'i', 'n'], dtype=object)}
        assert_array_dicts_equal(result, expected)

        reader = TextReader(StringIO(data), delimiter=':',
                            header=None,
                            error_bad_lines=False,
                            warn_bad_lines=True)
        reader.read()
        captured = capsys.readouterr()

        assert 'Skipping line 4' in captured.err
        assert 'Skipping line 6' in captured.err
开发者ID:forking-repos,项目名称:pandas,代码行数:35,代码来源:test_textreader.py

示例10: test_skipinitialspace

    def test_skipinitialspace(self):
        data = ('a,   b\n'
                'a,   b\n'
                'a,   b\n'
                'a,   b')

        reader = TextReader(StringIO(data), skipinitialspace=True,
                            header=None)
        result = reader.read()

        tm.assert_numpy_array_equal(result[0], np.array(['a', 'a', 'a', 'a'],
                                                        dtype=np.object_))
        tm.assert_numpy_array_equal(result[1], np.array(['b', 'b', 'b', 'b'],
                                                        dtype=np.object_))
开发者ID:forking-repos,项目名称:pandas,代码行数:14,代码来源:test_textreader.py

示例11: test_header_not_enough_lines

    def test_header_not_enough_lines(self):
        data = ('skip this\n'
                'skip this\n'
                'a,b,c\n'
                '1,2,3\n'
                '4,5,6')

        reader = TextReader(StringIO(data), delimiter=',', header=2)
        header = reader.header
        expected = [['a', 'b', 'c']]
        assert header == expected

        recs = reader.read()
        expected = {0: np.array([1, 4], dtype=np.int64),
                    1: np.array([2, 5], dtype=np.int64),
                    2: np.array([3, 6], dtype=np.int64)}
        assert_array_dicts_equal(recs, expected)
开发者ID:forking-repos,项目名称:pandas,代码行数:17,代码来源:test_textreader.py

示例12: test_header_not_enough_lines

    def test_header_not_enough_lines(self):
        data = ('skip this\n'
                'skip this\n'
                'a,b,c\n'
                '1,2,3\n'
                '4,5,6')

        reader = TextReader(StringIO(data), delimiter=',', header=2)
        header = reader.header
        expected = [['a', 'b', 'c']]
        assert header == expected

        recs = reader.read()
        expected = {0: [1, 4], 1: [2, 5], 2: [3, 6]}
        assert_array_dicts_equal(expected, recs)

        # not enough rows
        pytest.raises(parser.ParserError, TextReader, StringIO(data),
                      delimiter=',', header=5, as_recarray=True)
开发者ID:AllenDowney,项目名称:pandas,代码行数:19,代码来源:test_textreader.py

示例13: test_skip_bad_lines

    def test_skip_bad_lines(self):
        # too many lines, see #2430 for why
        data = ('a:b:c\n'
                'd:e:f\n'
                'g:h:i\n'
                'j:k:l:m\n'
                'l:m:n\n'
                'o:p:q:r')

        reader = TextReader(StringIO(data), delimiter=':',
                            header=None)
        pytest.raises(parser.ParserError, reader.read)

        reader = TextReader(StringIO(data), delimiter=':',
                            header=None,
                            error_bad_lines=False,
                            warn_bad_lines=False)
        result = reader.read()
        expected = {0: ['a', 'd', 'g', 'l'],
                    1: ['b', 'e', 'h', 'm'],
                    2: ['c', 'f', 'i', 'n']}
        assert_array_dicts_equal(result, expected)

        reader = TextReader(StringIO(data), delimiter=':',
                            header=None,
                            error_bad_lines=False,
                            warn_bad_lines=True)
        reader.read()
        val = sys.stderr.getvalue()

        assert 'Skipping line 4' in val
        assert 'Skipping line 6' in val
开发者ID:AllenDowney,项目名称:pandas,代码行数:32,代码来源:test_textreader.py

示例14: test_file_handle

 def test_file_handle(self):
     with open(self.csv1, 'rb') as f:
         reader = TextReader(f)
         reader.read()
开发者ID:forking-repos,项目名称:pandas,代码行数:4,代码来源:test_textreader.py

示例15: test_string_filename

 def test_string_filename(self):
     reader = TextReader(self.csv1, header=None)
     reader.read()
开发者ID:forking-repos,项目名称:pandas,代码行数:3,代码来源:test_textreader.py


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