Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions tests/series/arithmetic/test_truediv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import pandas as pd
from typing_extensions import assert_type

from tests import check
from tests import (
PD_LTE_23,
WINDOWS,
check,
)

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

Expand Down Expand Up @@ -140,15 +144,37 @@ def test_truediv_pd_series() -> None:
check(assert_type(left.rdiv(c), pd.Series), pd.Series)


def test_truediv_path() -> None:
"""Test pd.Series / path object"""
left, p = pd.Series(["pat", "ath", "path"]), Path()
def test_path_div(tmp_path: Path) -> None:
"""Test pd.Series of paths / path object.

check(assert_type(left / p, pd.Series), pd.Series, Path)
check(assert_type(p / left, pd.Series), pd.Series, Path)
Also GH 682."""
fpath = Path("a.png")
folders, fpaths = pd.Series([tmp_path, tmp_path]), pd.Series([fpath, fpath])

check(assert_type(left.truediv(p), pd.Series), pd.Series, Path)
check(assert_type(left.div(p), pd.Series), pd.Series, Path)
check(assert_type(folders / fpath, pd.Series), pd.Series, Path)
check(assert_type(folders.truediv(fpath), pd.Series), pd.Series, Path)
check(assert_type(folders.div(fpath), pd.Series), pd.Series, Path)

check(assert_type(left.rtruediv(p), pd.Series), pd.Series, Path)
check(assert_type(left.rdiv(p), pd.Series), pd.Series, Path)
check(assert_type(tmp_path / fpaths, pd.Series), pd.Series, Path)
check(assert_type(fpaths.rtruediv(tmp_path), pd.Series), pd.Series, Path)
check(assert_type(fpaths.rdiv(tmp_path), pd.Series), pd.Series, Path)


def test_truediv_path(tmp_path: Path) -> None:
"""Test pd.Series / path object.

Also GH 682."""
fnames = pd.Series(["a.png", "b.gz", "c.txt"])

if PD_LTE_23:
# Bug in 3.0 https://github.com/pandas-dev/pandas/issues/61940
check(assert_type(fnames / tmp_path, pd.Series), pd.Series, Path)
check(assert_type(tmp_path / fnames, pd.Series), pd.Series, Path)

if PD_LTE_23 or not WINDOWS:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The or not WINDOWS should not be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# pyarrow.lib.ArrowInvalid: Could not convert WindowsPath('...') with type WindowsPath: did not recognize Python value type when inferring an Arrow data type
check(assert_type(fnames.truediv(tmp_path), pd.Series), pd.Series, Path)
check(assert_type(fnames.div(tmp_path), pd.Series), pd.Series, Path)

check(assert_type(fnames.rtruediv(tmp_path), pd.Series), pd.Series, Path)
check(assert_type(fnames.rdiv(tmp_path), pd.Series), pd.Series, Path)
12 changes: 0 additions & 12 deletions tests/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3802,18 +3802,6 @@ def test_series_bool_fails() -> None:
pass


def test_path_div() -> None:
# GH 682
folder = Path.cwd()
files = pd.Series(["a.png", "b.png"])
if PD_LTE_23:
# Bug in 3.0 https://github.com/pandas-dev/pandas/issues/61940
check(assert_type(folder / files, pd.Series), pd.Series, Path)

folders = pd.Series([folder, folder])
check(assert_type(folders / Path("a.png"), pd.Series), pd.Series, Path)


def test_series_dict() -> None:
# GH 812
check(
Expand Down
Loading