|
1 | 1 | import functools
|
2 | 2 | import re
|
3 |
| -from typing import Any |
4 | 3 |
|
5 | 4 | import numpy as np
|
6 | 5 | import pandas as pd
|
7 |
| -import pytest |
8 | 6 | from typing_extensions import assert_type
|
9 | 7 |
|
10 | 8 | from tests import check
|
11 | 9 |
|
12 | 10 |
|
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: |
23 | 12 | data = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
|
24 | 13 | s = pd.Series(data)
|
25 | 14 | _check = functools.partial(check, klass=pd.Series, dtype=str)
|
@@ -52,6 +41,39 @@ def test_string_accessors_type_preserving_series(
|
52 | 41 | _check(assert_type(s.str.zfill(10), "pd.Series[str]"))
|
53 | 42 |
|
54 | 43 |
|
| 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 | + |
55 | 77 | def test_string_accessors_type_boolean():
|
56 | 78 | s = pd.Series(
|
57 | 79 | ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
|
|
0 commit comments