Skip to content

Commit fc2a0de

Browse files
Fix os.PathLike not compatible with pandas._typing.FilePathOrBuffer (#41)
* Fix os.PathLike not compatible with pandas._typing.FilePathOrBuffer * Refactoring test case * optimize imports Co-authored-by: joannasendorek <joanna.sendorek@tesco.com>
1 parent ef04842 commit fc2a0de

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def list_packages(source_path: str = src_path) -> None:
2121
setup(
2222
name="pandas-stubs",
2323
package_dir={"": src_path},
24-
version="1.1.0.5",
24+
version="1.1.0.6",
2525
description="Type annotations for Pandas",
2626
long_description=(open("README.md").read()
2727
if os.path.exists("README.md") else ""),

tests/snippets/test_frame.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# flake8: noqa: F841
2-
32
import tempfile
43
from pathlib import Path
54

@@ -14,7 +13,7 @@ def test_types_init() -> None:
1413
pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['a', 'b', 'c'], dtype=np.int8, copy=True)
1514

1615

17-
def test_types_csv() -> None:
16+
def test_types_to_csv() -> None:
1817
df = pd.DataFrame(data={'col1': [1, 2], 'col2': [3, 4]})
1918
csv_df: str = df.to_csv()
2019

@@ -32,6 +31,17 @@ def test_types_csv() -> None:
3231
df4: pd.DataFrame = pd.read_csv(file.name)
3332

3433

34+
def test_types_to_csv_when_path_passed() -> None:
35+
df = pd.DataFrame(data={'col1': [1, 2], 'col2': [3, 4]})
36+
path: Path = Path("./dummy_path.txt")
37+
try:
38+
assert not path.exists()
39+
df.to_csv(path)
40+
df5: pd.DataFrame = pd.read_csv(path)
41+
finally:
42+
path.unlink()
43+
44+
3545
def test_types_getitem() -> None:
3646
df = pd.DataFrame(data={'col1': [1, 2], 'col2': [3, 4], 5: [6, 7]})
3747
i = pd.Index(['col1', 'col2'])

third_party/3/pandas/_typing.pyi

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import datetime
44
import sys
55
from decimal import Decimal
66
from fractions import Fraction
7+
from io import RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper
8+
from mmap import mmap
9+
from os import PathLike
710
from numbers import Number
8-
from pathlib import Path
911

1012
from pandas.core.arrays.base import ExtensionArray as ExtensionArray
1113
from pandas.core.indexes.base import Index as Index
@@ -65,7 +67,12 @@ UserCorrelationMethod = Callable[[np.ndarray, np.ndarray], Scalar]
6567
CorrelationMethod = Union[NamedCorrelationMethod, UserCorrelationMethod]
6668

6769
Dtype: Any
68-
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]
70+
T = TypeVar('T')
71+
72+
Buffer = Union[IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]
73+
FileOrBuffer = Union[str, Buffer[T]]
74+
FilePathOrBuffer = Union["PathLike[str]", FileOrBuffer[T]]
75+
6976
FrameOrSeriesUnion: Union[DataFrame, Series]
7077
FrameOrSeries = Union[DataFrame, Series]
7178
Axis = Union[str, int]
@@ -76,8 +83,6 @@ JSONSerializable = Union[PythonScalar, List, Dict]
7683
Axes = Collection
7784
Renamer = Union[Mapping[Label, Any], Callable[[Label], Label]]
7885

79-
T = TypeVar('T')
80-
8186
FillValue = Union[Scalar, Dict[Any, Any], FrameOrSeries]
8287

8388
# Any plain Python or numpy function

0 commit comments

Comments
 (0)