diff --git a/pandas/_typing.py b/pandas/_typing.py index de02a549856ab..a99dc584f64ca 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -390,3 +390,13 @@ def closed(self) -> bool: ] AlignJoin = Literal["outer", "inner", "left", "right"] DtypeBackend = Literal["pyarrow", "numpy_nullable"] + +OpenFileErrors = Literal[ + "strict", + "ignore", + "replace", + "surrogateescape", + "xmlcharrefreplace", + "backslashreplace", + "namereplace", +] diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 582a043a8a78a..8d7d66a1f1504 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -68,6 +68,7 @@ Manager, NaPosition, NDFrameT, + OpenFileErrors, RandomState, Renamer, Scalar, @@ -2566,7 +2567,7 @@ def to_hdf( nan_rep=None, dropna: bool_t | None = None, data_columns: Literal[True] | list[str] | None = None, - errors: str = "strict", + errors: OpenFileErrors = "strict", encoding: str = "UTF-8", ) -> None: """ @@ -2713,7 +2714,7 @@ def to_sql( index_label: IndexLabel = None, chunksize: int | None = None, dtype: DtypeArg | None = None, - method: str | None = None, + method: Literal["multi"] | Callable | None = None, ) -> int | None: """ Write records stored in a DataFrame to a SQL database. @@ -3559,7 +3560,7 @@ def to_csv( doublequote: bool_t = ..., escapechar: str | None = ..., decimal: str = ..., - errors: str = ..., + errors: OpenFileErrors = ..., storage_options: StorageOptions = ..., ) -> str: ... @@ -3586,7 +3587,7 @@ def to_csv( doublequote: bool_t = ..., escapechar: str | None = ..., decimal: str = ..., - errors: str = ..., + errors: OpenFileErrors = ..., storage_options: StorageOptions = ..., ) -> None: ... @@ -3617,7 +3618,7 @@ def to_csv( doublequote: bool_t = True, escapechar: str | None = None, decimal: str = ".", - errors: str = "strict", + errors: OpenFileErrors = "strict", storage_options: StorageOptions = None, ) -> str | None: r""" @@ -4852,8 +4853,8 @@ def sort_values( axis: Axis = ..., ascending: bool_t | Sequence[bool_t] = ..., inplace: Literal[False] = ..., - kind: str = ..., - na_position: str = ..., + kind: SortKind = ..., + na_position: NaPosition = ..., ignore_index: bool_t = ..., key: ValueKeyFunc = ..., ) -> Self: @@ -4866,8 +4867,8 @@ def sort_values( axis: Axis = ..., ascending: bool_t | Sequence[bool_t] = ..., inplace: Literal[True], - kind: str = ..., - na_position: str = ..., + kind: SortKind = ..., + na_position: NaPosition = ..., ignore_index: bool_t = ..., key: ValueKeyFunc = ..., ) -> None: @@ -4880,8 +4881,8 @@ def sort_values( axis: Axis = ..., ascending: bool_t | Sequence[bool_t] = ..., inplace: bool_t = ..., - kind: str = ..., - na_position: str = ..., + kind: SortKind = ..., + na_position: NaPosition = ..., ignore_index: bool_t = ..., key: ValueKeyFunc = ..., ) -> Self | None: @@ -4893,8 +4894,8 @@ def sort_values( axis: Axis = 0, ascending: bool_t | Sequence[bool_t] = True, inplace: bool_t = False, - kind: str = "quicksort", - na_position: str = "last", + kind: SortKind = "quicksort", + na_position: NaPosition = "last", ignore_index: bool_t = False, key: ValueKeyFunc = None, ) -> Self | None: diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 0332cfb4adad7..d7f7a0b8801ed 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -23,6 +23,7 @@ from typing import ( TYPE_CHECKING, Any, + Callable, Iterator, Literal, Mapping, @@ -683,7 +684,7 @@ def to_sql( index_label: IndexLabel = None, chunksize: int | None = None, dtype: DtypeArg | None = None, - method: str | None = None, + method: Literal["multi"] | Callable | None = None, engine: str = "auto", **engine_kwargs, ) -> int | None: @@ -996,7 +997,9 @@ def insert_data(self) -> tuple[list[str], list[np.ndarray]]: return column_names, data_list def insert( - self, chunksize: int | None = None, method: str | None = None + self, + chunksize: int | None = None, + method: Literal["multi"] | Callable | None = None, ) -> int | None: # set insert method if method is None: @@ -1402,7 +1405,7 @@ def to_sql( schema=None, chunksize: int | None = None, dtype: DtypeArg | None = None, - method=None, + method: Literal["multi"] | Callable | None = None, engine: str = "auto", **engine_kwargs, ) -> int | None: @@ -1863,7 +1866,7 @@ def to_sql( schema: str | None = None, chunksize: int | None = None, dtype: DtypeArg | None = None, - method=None, + method: Literal["multi"] | Callable | None = None, engine: str = "auto", **engine_kwargs, ) -> int | None: @@ -2318,7 +2321,7 @@ def to_sql( schema=None, chunksize: int | None = None, dtype: DtypeArg | None = None, - method=None, + method: Literal["multi"] | Callable | None = None, engine: str = "auto", **engine_kwargs, ) -> int | None: