Skip to content

Commit d391bf2

Browse files
committed
Review
1 parent e4503dd commit d391bf2

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

pandas/io/common.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import codecs
66
from collections import abc
77
import dataclasses
8+
import functools
89
import gzip
910
from io import (
1011
BufferedIOBase,
@@ -1130,20 +1131,19 @@ def _is_binary_mode(handle: FilePath | BaseBuffer, mode: str) -> bool:
11301131
)
11311132

11321133

1133-
def _get_binary_io_classes(_cache: list[type] = []) -> tuple[type, ...]:
1134+
@functools.lru_cache
1135+
def _get_binary_io_classes() -> tuple[type, ...]:
11341136
"""IO classes that that expect bytes"""
1135-
if not _cache:
1136-
binary_classes: tuple[type, ...] = (BufferedIOBase, RawIOBase)
1137-
1138-
# python-zstandard doesn't use any of the builtin base classes; instead we
1139-
# have to use the `zstd.ZstdDecompressionReader` class for isinstance checks.
1140-
# Unfortunately `zstd.ZstdDecompressionReader` isn't exposed by python-zstandard
1141-
# so we have to get it from a `zstd.ZstdDecompressor` instance.
1142-
# See also https://github.com/indygreg/python-zstandard/pull/165.
1143-
zstd = import_optional_dependency("zstandard", errors="ignore")
1144-
if zstd is not None:
1145-
with zstd.ZstdDecompressor().stream_reader(b"") as reader:
1146-
binary_classes += (type(reader),)
1147-
1148-
_cache[:] = binary_classes
1149-
return tuple(_cache)
1137+
binary_classes: tuple[type, ...] = (BufferedIOBase, RawIOBase)
1138+
1139+
# python-zstandard doesn't use any of the builtin base classes; instead we
1140+
# have to use the `zstd.ZstdDecompressionReader` class for isinstance checks.
1141+
# Unfortunately `zstd.ZstdDecompressionReader` isn't exposed by python-zstandard
1142+
# so we have to get it from a `zstd.ZstdDecompressor` instance.
1143+
# See also https://github.com/indygreg/python-zstandard/pull/165.
1144+
zstd = import_optional_dependency("zstandard", errors="ignore")
1145+
if zstd is not None:
1146+
with zstd.ZstdDecompressor().stream_reader(b"") as reader:
1147+
binary_classes += (type(reader),)
1148+
1149+
return binary_classes

0 commit comments

Comments
 (0)