|
25 | 25 | import pandas._libs.lib as lib
|
26 | 26 | from pandas._typing import (
|
27 | 27 | ArrayLike,
|
28 |
| - FilePath, |
29 | 28 | ReadCsvBuffer,
|
30 | 29 | Scalar,
|
31 | 30 | )
|
|
51 | 50 |
|
52 | 51 |
|
53 | 52 | class PythonParser(ParserBase):
|
54 |
| - def __init__( |
55 |
| - self, f: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str] | list, **kwds |
56 |
| - ): |
| 53 | + def __init__(self, f: ReadCsvBuffer[str] | list, **kwds): |
57 | 54 | """
|
58 | 55 | Workhorse function for processing nested list into DataFrame
|
59 | 56 | """
|
60 |
| - ParserBase.__init__(self, kwds) |
| 57 | + super().__init__(kwds) |
61 | 58 |
|
62 | 59 | self.data: Iterator[str] | None = None
|
63 | 60 | self.buf: list = []
|
@@ -104,28 +101,18 @@ def __init__(
|
104 | 101 | # read_excel: f is a list
|
105 | 102 | self.data = cast(Iterator[str], f)
|
106 | 103 | else:
|
107 |
| - self._open_handles(f, kwds) |
108 |
| - assert self.handles is not None |
109 |
| - assert hasattr(self.handles.handle, "readline") |
110 |
| - try: |
111 |
| - self._make_reader(self.handles.handle) |
112 |
| - except (csv.Error, UnicodeDecodeError): |
113 |
| - self.close() |
114 |
| - raise |
| 104 | + assert hasattr(f, "readline") |
| 105 | + self._make_reader(f) |
115 | 106 |
|
116 | 107 | # Get columns in two steps: infer from data, then
|
117 | 108 | # infer column indices from self.usecols if it is specified.
|
118 | 109 | self._col_indices: list[int] | None = None
|
119 | 110 | columns: list[list[Scalar | None]]
|
120 |
| - try: |
121 |
| - ( |
122 |
| - columns, |
123 |
| - self.num_original_columns, |
124 |
| - self.unnamed_cols, |
125 |
| - ) = self._infer_columns() |
126 |
| - except (TypeError, ValueError): |
127 |
| - self.close() |
128 |
| - raise |
| 111 | + ( |
| 112 | + columns, |
| 113 | + self.num_original_columns, |
| 114 | + self.unnamed_cols, |
| 115 | + ) = self._infer_columns() |
129 | 116 |
|
130 | 117 | # Now self.columns has the set of columns that we will process.
|
131 | 118 | # The original set is stored in self.original_columns.
|
@@ -1259,9 +1246,7 @@ class FixedWidthFieldParser(PythonParser):
|
1259 | 1246 | See PythonParser for details.
|
1260 | 1247 | """
|
1261 | 1248 |
|
1262 |
| - def __init__( |
1263 |
| - self, f: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str], **kwds |
1264 |
| - ) -> None: |
| 1249 | + def __init__(self, f: ReadCsvBuffer[str], **kwds) -> None: |
1265 | 1250 | # Support iterators, convert to a list.
|
1266 | 1251 | self.colspecs = kwds.pop("colspecs")
|
1267 | 1252 | self.infer_nrows = kwds.pop("infer_nrows")
|
|
0 commit comments