Skip to content

Commit 385b1bd

Browse files
committed
split out into separate file
1 parent 45b8da0 commit 385b1bd

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

tests/test_string_accessors.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
import functools
22
import re
3-
from typing import Any
43

54
import numpy as np
65
import pandas as pd
7-
import pytest
86
from typing_extensions import assert_type
97

108
from tests import check
119

1210

13-
@pytest.mark.parametrize("constructor", ["series", "index"])
14-
@pytest.mark.parametrize(
15-
("method", "kwargs"),
16-
[
17-
("capitalize", {}),
18-
],
19-
)
20-
def test_string_accessors_type_preserving_series(
21-
constructor: Any, method: str, kwargs: Any
22-
) -> None:
11+
def test_string_accessors_type_preserving_series() -> None:
2312
data = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
2413
s = pd.Series(data)
2514
_check = functools.partial(check, klass=pd.Series, dtype=str)
@@ -52,6 +41,39 @@ def test_string_accessors_type_preserving_series(
5241
_check(assert_type(s.str.zfill(10), "pd.Series[str]"))
5342

5443

44+
def test_string_accessors_type_preserving_index() -> None:
45+
data = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
46+
idx = pd.Index(data)
47+
_check = functools.partial(check, klass=pd.Index, dtype=str)
48+
_check(assert_type(idx.str.capitalize(), "pd.Index[str]"))
49+
_check(assert_type(idx.str.casefold(), "pd.Index[str]"))
50+
check(assert_type(idx.str.cat(sep="X"), str), str)
51+
_check(assert_type(idx.str.center(10), "pd.Index[str]"))
52+
_check(assert_type(idx.str.get(2), "pd.Index[str]"))
53+
_check(assert_type(idx.str.ljust(80), "pd.Index[str]"))
54+
_check(assert_type(idx.str.lower(), "pd.Index[str]"))
55+
_check(assert_type(idx.str.lstrip("a"), "pd.Index[str]"))
56+
_check(assert_type(idx.str.normalize("NFD"), "pd.Index[str]"))
57+
_check(assert_type(idx.str.pad(80, "right"), "pd.Index[str]"))
58+
_check(assert_type(idx.str.removeprefix("a"), "pd.Index[str]"))
59+
_check(assert_type(idx.str.removesuffix("e"), "pd.Index[str]"))
60+
_check(assert_type(idx.str.repeat(2), "pd.Index[str]"))
61+
_check(assert_type(idx.str.replace("a", "X"), "pd.Index[str]"))
62+
_check(assert_type(idx.str.rjust(80), "pd.Index[str]"))
63+
_check(assert_type(idx.str.rstrip(), "pd.Index[str]"))
64+
_check(assert_type(idx.str.slice(0, 4, 2), "pd.Index[str]"))
65+
_check(assert_type(idx.str.slice_replace(0, 2, "XX"), "pd.Index[str]"))
66+
_check(assert_type(idx.str.strip(), "pd.Index[str]"))
67+
_check(assert_type(idx.str.swapcase(), "pd.Index[str]"))
68+
_check(assert_type(idx.str.title(), "pd.Index[str]"))
69+
_check(
70+
assert_type(idx.str.translate({241: "n"}), "pd.Index[str]"),
71+
)
72+
_check(assert_type(idx.str.upper(), "pd.Index[str]"))
73+
_check(assert_type(idx.str.wrap(80), "pd.Index[str]"))
74+
_check(assert_type(idx.str.zfill(10), "pd.Index[str]"))
75+
76+
5577
def test_string_accessors_type_boolean():
5678
s = pd.Series(
5779
["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]

0 commit comments

Comments
 (0)