(self)
| 1721 | self.open_bytes(b"") |
| 1722 | |
| 1723 | def test_column_options(self): |
| 1724 | # With column_names |
| 1725 | rows = b"1,2,3\n4,5,6" |
| 1726 | read_options = ReadOptions() |
| 1727 | read_options.column_names = ['d', 'e', 'f'] |
| 1728 | reader = self.open_bytes(rows, read_options=read_options) |
| 1729 | expected_schema = pa.schema([('d', pa.int64()), |
| 1730 | ('e', pa.int64()), |
| 1731 | ('f', pa.int64())]) |
| 1732 | self.check_reader(reader, expected_schema, |
| 1733 | [{'d': [1, 4], |
| 1734 | 'e': [2, 5], |
| 1735 | 'f': [3, 6]}]) |
| 1736 | |
| 1737 | # With include_columns |
| 1738 | convert_options = ConvertOptions() |
| 1739 | convert_options.include_columns = ['f', 'e'] |
| 1740 | reader = self.open_bytes(rows, read_options=read_options, |
| 1741 | convert_options=convert_options) |
| 1742 | expected_schema = pa.schema([('f', pa.int64()), |
| 1743 | ('e', pa.int64())]) |
| 1744 | self.check_reader(reader, expected_schema, |
| 1745 | [{'e': [2, 5], |
| 1746 | 'f': [3, 6]}]) |
| 1747 | |
| 1748 | # With column_types |
| 1749 | convert_options.column_types = {'e': pa.string()} |
| 1750 | reader = self.open_bytes(rows, read_options=read_options, |
| 1751 | convert_options=convert_options) |
| 1752 | expected_schema = pa.schema([('f', pa.int64()), |
| 1753 | ('e', pa.string())]) |
| 1754 | self.check_reader(reader, expected_schema, |
| 1755 | [{'e': ["2", "5"], |
| 1756 | 'f': [3, 6]}]) |
| 1757 | |
| 1758 | # Missing columns in include_columns |
| 1759 | convert_options.include_columns = ['g', 'f', 'e'] |
| 1760 | with pytest.raises( |
| 1761 | KeyError, |
| 1762 | match="Column 'g' in include_columns does not exist"): |
| 1763 | reader = self.open_bytes(rows, read_options=read_options, |
| 1764 | convert_options=convert_options) |
| 1765 | |
| 1766 | convert_options.include_missing_columns = True |
| 1767 | reader = self.open_bytes(rows, read_options=read_options, |
| 1768 | convert_options=convert_options) |
| 1769 | expected_schema = pa.schema([('g', pa.null()), |
| 1770 | ('f', pa.int64()), |
| 1771 | ('e', pa.string())]) |
| 1772 | self.check_reader(reader, expected_schema, |
| 1773 | [{'g': [None, None], |
| 1774 | 'e': ["2", "5"], |
| 1775 | 'f': [3, 6]}]) |
| 1776 | |
| 1777 | convert_options.column_types = {'e': pa.string(), 'g': pa.float64()} |
| 1778 | reader = self.open_bytes(rows, read_options=read_options, |
| 1779 | convert_options=convert_options) |
| 1780 | expected_schema = pa.schema([('g', pa.float64()), |
nothing calls this directly
no test coverage detected