|
5 | 5 | import pandas as pd
|
6 | 6 | from typing_extensions import assert_type
|
7 | 7 |
|
8 |
| -from tests import check |
| 8 | +from tests import ( |
| 9 | + PD_LTE_23, |
| 10 | + check, |
| 11 | +) |
9 | 12 |
|
10 | 13 | left = pd.DataFrame({"a": [1, 2, 3]})["a"] # left operand
|
11 | 14 |
|
@@ -140,15 +143,36 @@ def test_truediv_pd_series() -> None:
|
140 | 143 | check(assert_type(left.rdiv(c), pd.Series), pd.Series)
|
141 | 144 |
|
142 | 145 |
|
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. |
146 | 148 |
|
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]) |
149 | 152 |
|
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) |
152 | 156 |
|
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) |
0 commit comments