Skip to content

Commit 1fa75e8

Browse files
authored
fix: #1304 add PD_LTE_23 (#1306)
* fix: #1304 PD_LTE_23 #1304 (comment) * fix: pandas nightly * fix: mypy and naming * fix(comment): #1306 (comment)
1 parent 9a389ec commit 1fa75e8

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

tests/series/arithmetic/test_truediv.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import pandas as pd
66
from typing_extensions import assert_type
77

8-
from tests import check
8+
from tests import (
9+
PD_LTE_23,
10+
check,
11+
)
912

1013
left = pd.DataFrame({"a": [1, 2, 3]})["a"] # left operand
1114

@@ -140,15 +143,36 @@ def test_truediv_pd_series() -> None:
140143
check(assert_type(left.rdiv(c), pd.Series), pd.Series)
141144

142145

143-
def test_truediv_path() -> None:
144-
"""Test pd.Series / path object"""
145-
left, p = pd.Series(["pat", "ath", "path"]), Path()
146+
def test_truediv_paths(tmp_path: Path) -> None:
147+
"""Test pd.Series of paths / path object.
146148
147-
check(assert_type(left / p, pd.Series), pd.Series, Path)
148-
check(assert_type(p / left, pd.Series), pd.Series, Path)
149+
Also GH 682."""
150+
fpath = Path("a.png")
151+
folders, fpaths = pd.Series([tmp_path, tmp_path]), pd.Series([fpath, fpath])
149152

150-
check(assert_type(left.truediv(p), pd.Series), pd.Series, Path)
151-
check(assert_type(left.div(p), pd.Series), pd.Series, Path)
153+
check(assert_type(folders / fpath, pd.Series), pd.Series, Path)
154+
check(assert_type(folders.truediv(fpath), pd.Series), pd.Series, Path)
155+
check(assert_type(folders.div(fpath), pd.Series), pd.Series, Path)
152156

153-
check(assert_type(left.rtruediv(p), pd.Series), pd.Series, Path)
154-
check(assert_type(left.rdiv(p), pd.Series), pd.Series, Path)
157+
# mypy thinks it's `Path`, in contrast to Series.__rtruediv__(self, other: Path) -> Series: ...
158+
check(assert_type(tmp_path / fpaths, pd.Series), pd.Series, Path) # type: ignore[assert-type]
159+
check(assert_type(fpaths.rtruediv(tmp_path), pd.Series), pd.Series, Path)
160+
check(assert_type(fpaths.rdiv(tmp_path), pd.Series), pd.Series, Path)
161+
162+
163+
def test_truediv_path(tmp_path: Path) -> None:
164+
"""Test pd.Series / path object.
165+
166+
Also GH 682."""
167+
fnames = pd.Series(["a.png", "b.gz", "c.txt"])
168+
169+
if PD_LTE_23:
170+
# Bug in 3.0 https://github.com/pandas-dev/pandas/issues/61940 (pyarrow.lib.ArrowInvalid)
171+
check(assert_type(fnames / tmp_path, pd.Series), pd.Series, Path)
172+
check(assert_type(tmp_path / fnames, pd.Series), pd.Series, Path)
173+
174+
check(assert_type(fnames.truediv(tmp_path), pd.Series), pd.Series, Path)
175+
check(assert_type(fnames.div(tmp_path), pd.Series), pd.Series, Path)
176+
177+
check(assert_type(fnames.rtruediv(tmp_path), pd.Series), pd.Series, Path)
178+
check(assert_type(fnames.rdiv(tmp_path), pd.Series), pd.Series, Path)

tests/series/test_series.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,18 +3802,6 @@ def test_series_bool_fails() -> None:
38023802
pass
38033803

38043804

3805-
def test_path_div() -> None:
3806-
# GH 682
3807-
folder = Path.cwd()
3808-
files = pd.Series(["a.png", "b.png"])
3809-
if PD_LTE_23:
3810-
# Bug in 3.0 https://github.com/pandas-dev/pandas/issues/61940
3811-
check(assert_type(folder / files, pd.Series), pd.Series, Path)
3812-
3813-
folders = pd.Series([folder, folder])
3814-
check(assert_type(folders / Path("a.png"), pd.Series), pd.Series, Path)
3815-
3816-
38173805
def test_series_dict() -> None:
38183806
# GH 812
38193807
check(

0 commit comments

Comments
 (0)