Skip to content

Removed continued parametrization of FilePathOrBuffer #27719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import IO, TYPE_CHECKING, AnyStr, Optional, TypeVar, Union
from typing import IO, TYPE_CHECKING, Optional, TypeVar, Union

import numpy as np

Expand All @@ -22,7 +22,7 @@
ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray)
DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta")
Dtype = Union[str, np.dtype, "ExtensionDtype"]
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]
FilePathOrBuffer = Union[str, Path, IO]

FrameOrSeries = TypeVar("FrameOrSeries", "Series", "DataFrame")
Scalar = Union[str, int, float]
Expand Down
10 changes: 3 additions & 7 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import mmap
import os
import pathlib
from typing import IO, AnyStr, BinaryIO, Optional, TextIO, Type
from typing import IO, BinaryIO, Optional, TextIO, Type
from urllib.error import URLError # noqa
from urllib.parse import ( # noqa
urlencode,
Expand Down Expand Up @@ -96,9 +96,7 @@ def _is_url(url) -> bool:
return False


def _expand_user(
filepath_or_buffer: FilePathOrBuffer[AnyStr]
) -> FilePathOrBuffer[AnyStr]:
def _expand_user(filepath_or_buffer: FilePathOrBuffer) -> FilePathOrBuffer:
"""Return the argument with an initial component of ~ or ~user
replaced by that user's home directory.

Expand Down Expand Up @@ -126,9 +124,7 @@ def _validate_header_arg(header) -> None:
)


def _stringify_path(
filepath_or_buffer: FilePathOrBuffer[AnyStr]
) -> FilePathOrBuffer[AnyStr]:
def _stringify_path(filepath_or_buffer: FilePathOrBuffer) -> FilePathOrBuffer:
"""Attempt to convert a path-like object to a string.

Parameters
Expand Down
12 changes: 5 additions & 7 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def _get_formatter(self, i: Union[str, int]) -> Optional[Callable]:

@contextmanager
def get_buffer(
self, buf: Optional[FilePathOrBuffer[str]], encoding: Optional[str] = None
self, buf: Optional[FilePathOrBuffer], encoding: Optional[str] = None
):
if buf is not None:
buf = _stringify_path(buf)
Expand All @@ -491,9 +491,7 @@ def write_result(self, buf: IO[str]) -> None:
raise AbstractMethodError(self)

def get_result(
self,
buf: Optional[FilePathOrBuffer[str]] = None,
encoding: Optional[str] = None,
self, buf: Optional[FilePathOrBuffer] = None, encoding: Optional[str] = None
) -> Optional[str]:
with self.get_buffer(buf, encoding=encoding) as f:
self.write_result(buf=f)
Expand Down Expand Up @@ -861,12 +859,12 @@ def _join_multiline(self, *args) -> str:
st = ed
return "\n\n".join(str_lst)

def to_string(self, buf: Optional[FilePathOrBuffer[str]] = None) -> Optional[str]:
def to_string(self, buf: Optional[FilePathOrBuffer] = None) -> Optional[str]:
return self.get_result(buf=buf)

def to_latex(
self,
buf: Optional[FilePathOrBuffer[str]] = None,
buf: Optional[FilePathOrBuffer] = None,
column_format: Optional[str] = None,
longtable: bool = False,
encoding: Optional[str] = None,
Expand Down Expand Up @@ -904,7 +902,7 @@ def _format_col(self, i: int) -> List[str]:

def to_html(
self,
buf: Optional[FilePathOrBuffer[str]] = None,
buf: Optional[FilePathOrBuffer] = None,
classes: Optional[Union[str, List, Tuple]] = None,
notebook: bool = False,
border: Optional[int] = None,
Expand Down