Skip to content

Commit

Permalink
refactor: Remove _Reader._response
Browse files Browse the repository at this point in the history
Can't reproduce the original issue that led to adding this.
All backends are supporting `HTTPResponse` directly
  • Loading branch information
dangotbanned committed Nov 12, 2024
1 parent 69a72b6 commit 08101cc
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions altair/datasets/_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import urllib.request
from collections.abc import Mapping, Sequence
from functools import partial
from http.client import HTTPResponse
from importlib import import_module
from importlib.util import find_spec
from itertools import chain, islice
Expand Down Expand Up @@ -81,10 +80,6 @@
_METADATA: Final[Path] = Path(__file__).parent / "_metadata" / "metadata.parquet"


def _identity(_: _T, /) -> _T:
return _


class _Reader(Protocol[IntoDataFrameT, IntoFrameT]):
"""
Describes basic IO for remote & local tabular resources.
Expand Down Expand Up @@ -123,17 +118,6 @@ class _Reader(Protocol[IntoDataFrameT, IntoFrameT]):

_ENV_VAR: ClassVar[LiteralString] = "ALTAIR_DATASETS_DIR"
_opener: ClassVar[OpenerDirector] = urllib.request.build_opener()
_response: ClassVar[staticmethod[[HTTPResponse], Any]] = staticmethod(_identity)
"""
Backends that do not support `file-like objects`_, must override with conversion.
Used only for **remote** files, as *cached* files use a `pathlib.Path`_.
.. _file-like objects:
https://docs.python.org/3/glossary.html#term-file-object
.. _pathlib.Path:
https://docs.python.org/3/library/pathlib.html#pathlib.Path
"""

def read_fn(self, source: StrPath, /) -> Callable[..., IntoDataFrameT]:
suffix = validate_suffix(source, is_ext_read)
Expand Down Expand Up @@ -168,7 +152,7 @@ def dataset(
return fn(fp, **kwds)
else:
with self._opener.open(url) as f:
return fn(self._response(f), **kwds)
return fn(f, **kwds)

def url(
self,
Expand Down Expand Up @@ -295,8 +279,6 @@ def __init__(self, name: Literal["pandas[pyarrow]"], /) -> None:


class _PolarsReader(_Reader["pl.DataFrame", "pl.LazyFrame"]):
_response = staticmethod(HTTPResponse.read)

def __init__(self, name: _Polars, /) -> None:
self._name = _requirements(name)
if not TYPE_CHECKING:
Expand All @@ -311,8 +293,6 @@ def __init__(self, name: _Polars, /) -> None:


class _PolarsPyArrowReader(_Reader["pl.DataFrame", "pl.LazyFrame"]):
_response = staticmethod(HTTPResponse.read)

def __init__(self, name: Literal["polars[pyarrow]"], /) -> None:
_pl, _pa = _requirements(name)
self._name = name
Expand Down

0 comments on commit 08101cc

Please sign in to comment.