-
-
Notifications
You must be signed in to change notification settings - Fork 145
feat(index): append #1282
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
feat(index): append #1282
Changes from 8 commits
390e5d9
3a34057
45e0ad3
6c8ba76
3844062
ac0857b
67e6bde
fa3c401
d7a538d
fe5f1a9
1c75df6
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 |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
import datetime as dt | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
Union, | ||
cast, | ||
) | ||
|
||
import numpy as np | ||
|
@@ -1028,6 +1030,57 @@ def test_getitem() -> None: | |
check(assert_type(i0[[0, 2]], "pd.Index[str]"), pd.Index, str) | ||
|
||
|
||
def test_append_mix() -> None: | ||
"""Test pd.Index.append that gives pd.Index[Any]""" | ||
first = pd.Index([1]) | ||
second = pd.Index(["a"]) | ||
third = pd.Index([1, "a"]) | ||
check(assert_type(first.append(second), "pd.Index[int | str]"), pd.Index) | ||
check(assert_type(first.append([second]), pd.Index), pd.Index) | ||
|
||
check( | ||
assert_type( # type: ignore[assert-type] | ||
first.append(third), "pd.Index[int | str]" | ||
Dr-Irv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
pd.Index, | ||
) | ||
check(assert_type(first.append([third]), pd.Index), pd.Index) | ||
check(assert_type(first.append([second, third]), pd.Index), pd.Index) | ||
|
||
check( | ||
assert_type( # type: ignore[assert-type] | ||
third.append([]), "pd.Index[int | str]" | ||
), | ||
pd.Index, | ||
) | ||
check( | ||
assert_type( # type: ignore[assert-type] | ||
third.append(cast("list[Index[Any]]", [])), "pd.Index[int | str]" | ||
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. Change these to 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 added comments in fe5f1a9.
I tend to believe this is a 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. After all, 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. How about 1c75df6? I am trying to get rid of 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. That is fine. Have to wonder if we should change |
||
), | ||
pd.Index, | ||
) | ||
check(assert_type(third.append([first]), pd.Index), pd.Index) | ||
check(assert_type(third.append([first, second]), pd.Index), pd.Index) | ||
|
||
|
||
def test_append_int() -> None: | ||
"""Test pd.Index[int].append""" | ||
first = pd.Index([1]) | ||
second = pd.Index([2]) | ||
check(assert_type(first.append([]), "pd.Index[int]"), pd.Index, np.int64) | ||
check(assert_type(first.append(second), "pd.Index[int]"), pd.Index, np.int64) | ||
check(assert_type(first.append([second]), "pd.Index[int]"), pd.Index, np.int64) | ||
|
||
|
||
def test_append_str() -> None: | ||
"""Test pd.Index[str].append""" | ||
first = pd.Index(["str"]) | ||
second = pd.Index(["rts"]) | ||
check(assert_type(first.append([]), "pd.Index[str]"), pd.Index, str) | ||
check(assert_type(first.append(second), "pd.Index[str]"), pd.Index, str) | ||
check(assert_type(first.append([second]), "pd.Index[str]"), pd.Index, str) | ||
|
||
|
||
def test_range_index_range() -> None: | ||
"""Test that pd.RangeIndex can be initialized from range.""" | ||
iri = pd.RangeIndex(range(5)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really want to avoid having the union types here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d7a538d