|
6 | 6 |
|
7 | 7 | from __future__ import annotations
|
8 | 8 |
|
9 |
| -from collections import ( |
10 |
| - abc, |
11 |
| - defaultdict, |
12 |
| -) |
13 | 9 | import csv
|
14 | 10 | import sys
|
15 |
| -from textwrap import fill |
16 |
| -from typing import ( |
17 |
| - IO, |
18 |
| - TYPE_CHECKING, |
19 |
| - Any, |
20 |
| - Generic, |
21 |
| - Literal, |
22 |
| - TypedDict, |
23 |
| - overload, |
24 |
| -) |
25 | 11 | import warnings
|
| 12 | +from collections import abc, defaultdict |
| 13 | +from textwrap import fill |
| 14 | +from typing import IO, TYPE_CHECKING, Any, Generic, Literal, TypedDict, overload |
26 | 15 |
|
27 | 16 | import numpy as np
|
28 | 17 |
|
| 18 | +from pandas import Series |
29 | 19 | from pandas._libs import lib
|
30 | 20 | from pandas._libs.parsers import STR_NA_VALUES
|
31 |
| -from pandas.errors import ( |
32 |
| - AbstractMethodError, |
33 |
| - ParserWarning, |
34 |
| -) |
35 |
| -from pandas.util._decorators import Appender |
36 |
| -from pandas.util._exceptions import find_stack_level |
37 |
| -from pandas.util._validators import check_dtype_backend |
38 |
| - |
39 | 21 | from pandas.core.dtypes.common import (
|
40 | 22 | is_file_like,
|
41 | 23 | is_float,
|
42 | 24 | is_integer,
|
43 | 25 | is_list_like,
|
44 | 26 | pandas_dtype,
|
45 | 27 | )
|
46 |
| - |
47 |
| -from pandas import Series |
48 | 28 | from pandas.core.frame import DataFrame
|
49 | 29 | from pandas.core.indexes.api import RangeIndex
|
50 | 30 | from pandas.core.shared_docs import _shared_docs
|
51 |
| - |
52 |
| -from pandas.io.common import ( |
53 |
| - IOHandles, |
54 |
| - get_handle, |
55 |
| - stringify_path, |
56 |
| - validate_header_arg, |
57 |
| -) |
| 31 | +from pandas.errors import AbstractMethodError, ParserWarning |
| 32 | +from pandas.io.common import IOHandles, get_handle, stringify_path, validate_header_arg |
58 | 33 | from pandas.io.parsers.arrow_parser_wrapper import ArrowParserWrapper
|
59 |
| -from pandas.io.parsers.base_parser import ( |
60 |
| - ParserBase, |
61 |
| - is_index_col, |
62 |
| - parser_defaults, |
63 |
| -) |
| 34 | +from pandas.io.parsers.base_parser import ParserBase, is_index_col, parser_defaults |
64 | 35 | from pandas.io.parsers.c_parser_wrapper import CParserWrapper
|
65 |
| -from pandas.io.parsers.python_parser import ( |
66 |
| - FixedWidthFieldParser, |
67 |
| - PythonParser, |
68 |
| -) |
| 36 | +from pandas.io.parsers.python_parser import FixedWidthFieldParser, PythonParser |
| 37 | +from pandas.util._decorators import Appender |
| 38 | +from pandas.util._exceptions import find_stack_level |
| 39 | +from pandas.util._validators import check_dtype_backend |
69 | 40 |
|
70 | 41 | if TYPE_CHECKING:
|
71 |
| - from collections.abc import ( |
72 |
| - Callable, |
73 |
| - Hashable, |
74 |
| - Iterable, |
75 |
| - Mapping, |
76 |
| - Sequence, |
77 |
| - ) |
| 42 | + from collections.abc import Callable, Hashable, Iterable, Mapping, Sequence |
78 | 43 | from types import TracebackType
|
79 | 44 |
|
80 | 45 | from pandas._typing import (
|
@@ -138,6 +103,7 @@ class _read_shared(TypedDict, Generic[HashableT], total=False):
|
138 | 103 | float_precision: Literal["high", "legacy", "round_trip"] | None
|
139 | 104 | storage_options: StorageOptions | None
|
140 | 105 | dtype_backend: DtypeBackend | lib.NoDefault
|
| 106 | + |
141 | 107 | else:
|
142 | 108 | _read_shared = dict
|
143 | 109 |
|
@@ -321,20 +287,18 @@ class _read_shared(TypedDict, Generic[HashableT], total=False):
|
321 | 287 |
|
322 | 288 | Note: A fast-path exists for iso8601-formatted dates.
|
323 | 289 | date_format : str or dict of column -> format, optional
|
324 |
| - Format to use for parsing dates when used in conjunction with ``parse_dates``. |
325 |
| - The strftime to parse time, e.g. :const:`"%d/%m/%Y"`. See |
326 |
| - `strftime documentation |
327 |
| - <https://docs.python.org/3/library/datetime.html |
328 |
| - #strftime-and-strptime-behavior>`_ for more information on choices, though |
329 |
| - note that :const:`"%f"` will parse all the way up to nanoseconds. |
330 |
| - You can also pass: |
331 |
| -
|
332 |
| - - "ISO8601", to parse any `ISO8601 <https://en.wikipedia.org/wiki/ISO_8601>`_ |
333 |
| - time string (not necessarily in exactly the same format); |
334 |
| - - "mixed", to infer the format for each element individually. This is risky, |
335 |
| - and you should probably use it along with `dayfirst`. |
| 290 | + Format to use for parsing dates and/or times when used in conjunction with ``parse_dates``. |
| 291 | + This format should be specified using the `strftime` directives (e.g., :const:`"%d/%m/%Y"`). |
| 292 | + Refer to the `strftime documentation <https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior>`_ |
| 293 | + for more details on format choices. Note that :const:`"%f"` will parse all the way up to nanoseconds. |
| 294 | +
|
| 295 | + You can also pass the following special values: |
| 296 | +
|
| 297 | + - "ISO8601": To parse any `ISO8601 <https://en.wikipedia.org/wiki/ISO_8601>`_ time string (not necessarily in exactly the same format). |
| 298 | + - "mixed": To infer the format for each element individually. This is less predictable and should generally be used with `dayfirst` for safer parsing. |
336 | 299 |
|
337 | 300 | .. versionadded:: 2.0.0
|
| 301 | + |
338 | 302 | dayfirst : bool, default False
|
339 | 303 | DD/MM format dates, international and European format.
|
340 | 304 | cache_dates : bool, default True
|
@@ -792,10 +756,9 @@ def read_csv(
|
792 | 756 | skipfooter: int = 0,
|
793 | 757 | nrows: int | None = None,
|
794 | 758 | # NA and Missing Data Handling
|
795 |
| - na_values: Hashable |
796 |
| - | Iterable[Hashable] |
797 |
| - | Mapping[Hashable, Iterable[Hashable]] |
798 |
| - | None = None, |
| 759 | + na_values: ( |
| 760 | + Hashable | Iterable[Hashable] | Mapping[Hashable, Iterable[Hashable]] | None |
| 761 | + ) = None, |
799 | 762 | keep_default_na: bool = True,
|
800 | 763 | na_filter: bool = True,
|
801 | 764 | skip_blank_lines: bool = True,
|
@@ -927,10 +890,9 @@ def read_table(
|
927 | 890 | skipfooter: int = 0,
|
928 | 891 | nrows: int | None = None,
|
929 | 892 | # NA and Missing Data Handling
|
930 |
| - na_values: Hashable |
931 |
| - | Iterable[Hashable] |
932 |
| - | Mapping[Hashable, Iterable[Hashable]] |
933 |
| - | None = None, |
| 893 | + na_values: ( |
| 894 | + Hashable | Iterable[Hashable] | Mapping[Hashable, Iterable[Hashable]] | None |
| 895 | + ) = None, |
934 | 896 | keep_default_na: bool = True,
|
935 | 897 | na_filter: bool = True,
|
936 | 898 | skip_blank_lines: bool = True,
|
|
0 commit comments