Skip to content

Commit 9a9462b

Browse files
author
Kevin Sheppard
committed
MAINT: Correct typing issues
1 parent 74b0cbf commit 9a9462b

File tree

7 files changed

+73
-112
lines changed

7 files changed

+73
-112
lines changed

pandas-stubs/_libs/lib.pyi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
from enum import Enum
2-
31
no_default = None
42

5-
class NoDefault(Enum):
6-
no_default: int
7-
83
def infer_dtype(value: object, skipna: bool = ...) -> str: ...

pandas-stubs/_typing.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ JsonSeriesOrient = Literal["split", "records", "index"]
242242
TimestampConvention = Literal["start", "end", "s", "e"]
243243

244244
CSVEngine = Literal["c", "python", "pyarrow", "python-fwf"]
245+
CSVQuoting = Literal[0, 1, 2, 3]
245246

246247
HDFCompLib = Literal["zlib", "lzo", "bzip2", "blosc"]
247248
ParquetEngine = Literal["auto", "pyarrow", "fastparquet"]

pandas-stubs/io/clipboards.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from pandas.core.series import Series
1515
from pandas._typing import (
1616
CompressionOptions,
1717
CSVEngine,
18+
CSVQuoting,
1819
DtypeArg,
1920
StorageOptions,
2021
npt,
@@ -71,7 +72,7 @@ def read_clipboard(
7172
decimal: str = ...,
7273
lineterminator: str | None = ...,
7374
quotechar: str = ...,
74-
quoting: int = ...,
75+
quoting: CSVQuoting | None = ...,
7576
doublequote: bool = ...,
7677
escapechar: str | None = ...,
7778
comment: str | None = ...,
@@ -137,7 +138,7 @@ def read_clipboard(
137138
decimal: str = ...,
138139
lineterminator: str | None = ...,
139140
quotechar: str = ...,
140-
quoting: int = ...,
141+
quoting: CSVQuoting | None = ...,
141142
doublequote: bool = ...,
142143
escapechar: str | None = ...,
143144
comment: str | None = ...,
@@ -203,7 +204,7 @@ def read_clipboard(
203204
decimal: str = ...,
204205
lineterminator: str | None = ...,
205206
quotechar: str = ...,
206-
quoting: int = ...,
207+
quoting: CSVQuoting | None = ...,
207208
doublequote: bool = ...,
208209
escapechar: str | None = ...,
209210
comment: str | None = ...,

pandas-stubs/io/parsers/base_parser.pyi

Lines changed: 0 additions & 35 deletions
This file was deleted.

pandas-stubs/io/parsers/readers.pyi

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import pandas._libs.lib as lib
1717
from pandas._typing import (
1818
CompressionOptions,
1919
CSVEngine,
20+
CSVQuoting,
2021
DtypeArg,
2122
FilePath,
2223
ReadCsvBuffer,
@@ -30,10 +31,10 @@ from pandas.io.common import IOHandles
3031
def read_csv(
3132
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
3233
*,
33-
sep: str | None | lib.NoDefault = ...,
34-
delimiter: str | None | lib.NoDefault = ...,
34+
sep: str | None = ...,
35+
delimiter: str | None = ...,
3536
header: int | Sequence[int] | Literal["infer"] | None = ...,
36-
names: list[str] | None | lib.NoDefault = ...,
37+
names: list[str] | None = ...,
3738
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
3839
usecols: list[str]
3940
| tuple[str, ...]
@@ -74,7 +75,7 @@ def read_csv(
7475
decimal: str = ...,
7576
lineterminator: str | None = ...,
7677
quotechar: str = ...,
77-
quoting: int = ...,
78+
quoting: CSVQuoting | None = ...,
7879
doublequote: bool = ...,
7980
escapechar: str | None = ...,
8081
comment: str | None = ...,
@@ -93,10 +94,10 @@ def read_csv(
9394
def read_csv(
9495
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
9596
*,
96-
sep: str | None | lib.NoDefault = ...,
97-
delimiter: str | None | lib.NoDefault = ...,
97+
sep: str | None = ...,
98+
delimiter: str | None = ...,
9899
header: int | Sequence[int] | Literal["infer"] | None = ...,
99-
names: list[str] | None | lib.NoDefault = ...,
100+
names: list[str] | None = ...,
100101
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
101102
usecols: list[str]
102103
| tuple[str, ...]
@@ -137,7 +138,7 @@ def read_csv(
137138
decimal: str = ...,
138139
lineterminator: str | None = ...,
139140
quotechar: str = ...,
140-
quoting: int = ...,
141+
quoting: CSVQuoting | None = ...,
141142
doublequote: bool = ...,
142143
escapechar: str | None = ...,
143144
comment: str | None = ...,
@@ -156,10 +157,10 @@ def read_csv(
156157
def read_csv(
157158
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
158159
*,
159-
sep: str | None | lib.NoDefault = ...,
160-
delimiter: str | None | lib.NoDefault = ...,
160+
sep: str | None = ...,
161+
delimiter: str | None = ...,
161162
header: int | Sequence[int] | Literal["infer"] | None = ...,
162-
names: list[str] | None | lib.NoDefault = ...,
163+
names: list[str] | None = ...,
163164
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
164165
usecols: list[str]
165166
| tuple[str, ...]
@@ -200,7 +201,7 @@ def read_csv(
200201
decimal: str = ...,
201202
lineterminator: str | None = ...,
202203
quotechar: str = ...,
203-
quoting: int = ...,
204+
quoting: CSVQuoting | None = ...,
204205
doublequote: bool = ...,
205206
escapechar: str | None = ...,
206207
comment: str | None = ...,
@@ -219,10 +220,10 @@ def read_csv(
219220
def read_table(
220221
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
221222
*,
222-
sep: str | None | lib.NoDefault = ...,
223-
delimiter: str | None | lib.NoDefault = ...,
223+
sep: str | None = ...,
224+
delimiter: str | None = ...,
224225
header: int | Sequence[int] | Literal["infer"] | None = ...,
225-
names: list[str] | None | lib.NoDefault = ...,
226+
names: list[str] | None = ...,
226227
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
227228
usecols: list[str]
228229
| tuple[str, ...]
@@ -263,7 +264,7 @@ def read_table(
263264
decimal: str = ...,
264265
lineterminator: str | None = ...,
265266
quotechar: str = ...,
266-
quoting: int = ...,
267+
quoting: CSVQuoting | None = ...,
267268
doublequote: bool = ...,
268269
escapechar: str | None = ...,
269270
comment: str | None = ...,
@@ -282,10 +283,10 @@ def read_table(
282283
def read_table(
283284
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
284285
*,
285-
sep: str | None | lib.NoDefault = ...,
286-
delimiter: str | None | lib.NoDefault = ...,
286+
sep: str | None = ...,
287+
delimiter: str | None = ...,
287288
header: int | Sequence[int] | Literal["infer"] | None = ...,
288-
names: list[str] | None | lib.NoDefault = ...,
289+
names: list[str] | None = ...,
289290
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
290291
usecols: list[str]
291292
| tuple[str, ...]
@@ -326,7 +327,7 @@ def read_table(
326327
decimal: str = ...,
327328
lineterminator: str | None = ...,
328329
quotechar: str = ...,
329-
quoting: int = ...,
330+
quoting: CSVQuoting | None = ...,
330331
doublequote: bool = ...,
331332
escapechar: str | None = ...,
332333
comment: str | None = ...,
@@ -345,10 +346,10 @@ def read_table(
345346
def read_table(
346347
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
347348
*,
348-
sep: str | None | lib.NoDefault = ...,
349-
delimiter: str | None | lib.NoDefault = ...,
349+
sep: str | None = ...,
350+
delimiter: str | None = ...,
350351
header: int | Sequence[int] | Literal["infer"] | None = ...,
351-
names: list[str] | None | lib.NoDefault = ...,
352+
names: list[str] | None = ...,
352353
index_col: int | str | Sequence[str | int] | Literal[False] | None = ...,
353354
usecols: list[str]
354355
| tuple[str, ...]
@@ -389,7 +390,7 @@ def read_table(
389390
decimal: str = ...,
390391
lineterminator: str | None = ...,
391392
quotechar: str = ...,
392-
quoting: int = ...,
393+
quoting: CSVQuoting | None = ...,
393394
doublequote: bool = ...,
394395
escapechar: str | None = ...,
395396
comment: str | None = ...,

tests/test_io.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Union,
88
)
99

10+
import numpy as np
1011
from packaging.version import parse
1112
import pandas as pd
1213
from pandas import (
@@ -367,6 +368,48 @@ def test_read_csv_iterator():
367368
)
368369

369370

371+
def test_types_read_csv() -> None:
372+
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
373+
csv_df: str = df.to_csv()
374+
375+
with ensure_clean() as path:
376+
df.to_csv(path)
377+
df2: pd.DataFrame = pd.read_csv(path)
378+
df3: pd.DataFrame = pd.read_csv(path, sep="a")
379+
df4: pd.DataFrame = pd.read_csv(
380+
path,
381+
header=None,
382+
)
383+
df5: pd.DataFrame = pd.read_csv(
384+
path, engine="python", true_values=["no", "No", "NO"], na_filter=False
385+
)
386+
df6: pd.DataFrame = pd.read_csv(
387+
path,
388+
skiprows=lambda x: x in [0, 2],
389+
skip_blank_lines=True,
390+
dayfirst=False,
391+
)
392+
df7: pd.DataFrame = pd.read_csv(path, nrows=2)
393+
df8: pd.DataFrame = pd.read_csv(path, dtype={"a": float, "b": int})
394+
df9: pd.DataFrame = pd.read_csv(path, usecols=["col1"])
395+
df10: pd.DataFrame = pd.read_csv(path, usecols=[0])
396+
df11: pd.DataFrame = pd.read_csv(path, usecols=np.array([0]))
397+
df12: pd.DataFrame = pd.read_csv(path, usecols=("col1",))
398+
df13: pd.DataFrame = pd.read_csv(path, usecols=pd.Series(data=["col1"]))
399+
400+
tfr1: TextFileReader = pd.read_csv(path, nrows=2, iterator=True, chunksize=3)
401+
tfr1.close()
402+
403+
tfr2: TextFileReader = pd.read_csv(path, nrows=2, chunksize=1)
404+
tfr2.close()
405+
406+
tfr3: TextFileReader = pd.read_csv(path, nrows=2, iterator=False, chunksize=1)
407+
tfr3.close()
408+
409+
tfr4: TextFileReader = pd.read_csv(path, nrows=2, iterator=True)
410+
tfr4.close()
411+
412+
370413
def test_read_table():
371414
with ensure_clean() as path:
372415
check(assert_type(DF.to_csv(path, sep="\t"), None), type(None))

tests/test_pandas.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88

99
import numpy as np
1010
import pandas as pd
11-
from pandas._testing import ensure_clean
1211
from pandas.api.extensions import ExtensionArray
1312
from typing_extensions import assert_type
1413

1514
from tests import check
1615

17-
from pandas.io.parsers import TextFileReader
18-
1916

2017
def test_types_to_datetime() -> None:
2118
df = pd.DataFrame({"year": [2015, 2016], "month": [2, 3], "day": [4, 5]})
@@ -114,48 +111,6 @@ def test_types_json_normalize() -> None:
114111
df5: pd.DataFrame = pd.json_normalize(data=data2)
115112

116113

117-
def test_types_read_csv() -> None:
118-
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
119-
csv_df: str = df.to_csv()
120-
121-
with ensure_clean() as path:
122-
df.to_csv(path)
123-
df2: pd.DataFrame = pd.read_csv(path)
124-
df3: pd.DataFrame = pd.read_csv(path, sep="a")
125-
df4: pd.DataFrame = pd.read_csv(
126-
path,
127-
header=None,
128-
)
129-
df5: pd.DataFrame = pd.read_csv(
130-
path, engine="python", true_values=["no", "No", "NO"], na_filter=False
131-
)
132-
df6: pd.DataFrame = pd.read_csv(
133-
path,
134-
skiprows=lambda x: x in [0, 2],
135-
skip_blank_lines=True,
136-
dayfirst=False,
137-
)
138-
df7: pd.DataFrame = pd.read_csv(path, nrows=2)
139-
df8: pd.DataFrame = pd.read_csv(path, dtype={"a": float, "b": int})
140-
df9: pd.DataFrame = pd.read_csv(path, usecols=["col1"])
141-
df10: pd.DataFrame = pd.read_csv(path, usecols=[0])
142-
df11: pd.DataFrame = pd.read_csv(path, usecols=np.array([0]))
143-
df12: pd.DataFrame = pd.read_csv(path, usecols=("col1",))
144-
df13: pd.DataFrame = pd.read_csv(path, usecols=pd.Series(data=["col1"]))
145-
146-
tfr1: TextFileReader = pd.read_csv(path, nrows=2, iterator=True, chunksize=3)
147-
tfr1.close()
148-
149-
tfr2: TextFileReader = pd.read_csv(path, nrows=2, chunksize=1)
150-
tfr2.close()
151-
152-
tfr3: TextFileReader = pd.read_csv(path, nrows=2, iterator=False, chunksize=1)
153-
tfr3.close()
154-
155-
tfr4: TextFileReader = pd.read_csv(path, nrows=2, iterator=True)
156-
tfr4.close()
157-
158-
159114
def test_isna() -> None:
160115
s = pd.Series([1, np.nan, 3.2])
161116
check(assert_type(pd.isna(s), "pd.Series[bool]"), pd.Series, bool)

0 commit comments

Comments
 (0)