-
-
Notifications
You must be signed in to change notification settings - Fork 144
GH1139 Series.rename inplace #1140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
64575f6
36de55b
d65a325
1b6e4c7
17a1049
470ccf4
5f18c66
a043807
2925083
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ | |
TimedeltaSeries: TypeAlias = pd.Series | ||
TimestampSeries: TypeAlias = pd.Series | ||
OffsetSeries: TypeAlias = pd.Series | ||
ExtensionArray: TypeAlias = np.ndarray | ||
|
||
if TYPE_CHECKING: | ||
from pandas._typing import ( | ||
|
@@ -1137,7 +1138,7 @@ def test_types_set_flags() -> None: | |
|
||
def test_types_getitem() -> None: | ||
s = pd.Series({"key": [0, 1, 2, 3]}) | ||
key: list[int] = s["key"] | ||
Dr-Irv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
check(assert_type(s["key"], Any), list) | ||
s2 = pd.Series([0, 1, 2, 3]) | ||
check(assert_type(s2[0], int), np.integer) | ||
check(assert_type(s[:2], pd.Series), pd.Series) | ||
|
@@ -1180,12 +1181,28 @@ def test_types_rename_axis() -> None: | |
|
||
|
||
def test_types_values() -> None: | ||
n1: np.ndarray | ExtensionArray = pd.Series([1, 2, 3]).values | ||
n2: np.ndarray | ExtensionArray = pd.Series(list("aabc")).values | ||
n3: np.ndarray | ExtensionArray = pd.Series(list("aabc")).astype("category").values | ||
n4: np.ndarray | ExtensionArray = pd.Series( | ||
pd.date_range("20130101", periods=3, tz="US/Eastern") | ||
).values | ||
check( | ||
assert_type(pd.Series([1, 2, 3]).values, "np.ndarray | ExtensionArray"), | ||
np.ndarray, | ||
) | ||
check( | ||
assert_type(pd.Series(list("aabc")).values, " np.ndarray | ExtensionArray "), | ||
np.ndarray, | ||
) | ||
check( | ||
assert_type( | ||
pd.Series(list("aabc")).astype("category").values, | ||
"np.ndarray | ExtensionArray", | ||
), | ||
pd.Categorical, | ||
) | ||
check( | ||
assert_type( | ||
pd.Series(pd.date_range("20130101", periods=3, tz="US/Eastern")).values, | ||
"np.ndarray | ExtensionArray", | ||
), | ||
np.ndarray, | ||
) | ||
|
||
|
||
def test_types_rename() -> None: | ||
|
@@ -1211,8 +1228,26 @@ def add1(x: int) -> int: | |
s5 = pd.Series([1, 2, 3]).rename({1: 10}) | ||
check(assert_type(s5, "pd.Series[int]"), pd.Series, np.integer) | ||
# inplace | ||
# TODO fix issue with inplace=True returning a Series, cf pandas #60942 | ||
s6: None = pd.Series([1, 2, 3]).rename("A", inplace=True) | ||
check( | ||
assert_type(pd.Series([1, 2, 3]).rename("A", inplace=True), "pd.Series[int]"), | ||
pd.Series, | ||
np.integer, | ||
) | ||
check( | ||
assert_type(pd.Series([1, 2, 3]).rename({1: 4, 2: 5}, inplace=True), None), | ||
type(None), | ||
) | ||
check( | ||
assert_type( | ||
pd.Series([1, 2, 3]).rename(index=None, inplace=True), "pd.Series[int]" | ||
), | ||
pd.Series, | ||
np.integer, | ||
) | ||
# TODO this should not raise an error, the lambda is matched with Hashable | ||
# check( | ||
# assert_type(pd.Series([1, 2, 3]).rename(lambda x: x**2, inplace=True), None), type(None) | ||
# ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the solution here is to not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I do so mypy seems to match the return of the expression with Any instead of None, let me see how I can address There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have pushed for you to take a look but not sure how to address, this is a mypy issue and not pyright, pyright is happy with the current setup and does not flag it. |
||
|
||
if TYPE_CHECKING_INVALID_USAGE: | ||
s7 = pd.Series([1, 2, 3]).rename({1: [3, 4, 5]}) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] | ||
Dr-Irv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
Uh oh!
There was an error while loading. Please reload this page.