-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Parse IntervalArray and IntervalIndex from strings #41451
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 18 commits
00c7e52
d2625a5
88f4f69
27ae2bf
e6e072a
6c1b871
5fd1526
d646802
1355a17
ec8a4cb
ab76e68
162045a
e702840
f8ab67c
0137f3e
a8cc3b2
cb2ec12
27a5a2e
40af75d
cffc164
8b29251
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from typing import ( | ||
Any, | ||
Hashable, | ||
Sequence, | ||
) | ||
|
||
import numpy as np | ||
|
@@ -317,6 +318,34 @@ def from_tuples( | |
arr = IntervalArray.from_tuples(data, closed=closed, copy=copy, dtype=dtype) | ||
return cls._simple_new(arr, name=name) | ||
|
||
@classmethod | ||
@Appender( | ||
_interval_shared_docs["from_strings"] | ||
% { | ||
"klass": "IntervalIndex", | ||
"examples": textwrap.dedent( | ||
"""\ | ||
Examples | ||
-------- | ||
>>> pd.IntervalIndex.from_strings(["(0, 1]", "(1, 2]"]) | ||
IntervalIndex([(0, 1], (1, 2]], | ||
dtype='interval[int64, right]') | ||
""" | ||
), | ||
} | ||
) | ||
def from_strings( | ||
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. why are you adding public api here? 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. By making it public, do you mean with the If the latter, how would one otherwise use this function? |
||
cls, | ||
data: Sequence[str], | ||
closed: str = "right", | ||
dtype: Dtype | None = None, | ||
name: Hashable = None, | ||
) -> IntervalIndex: | ||
with rewrite_exception("IntervalArray", cls.__name__): | ||
arr = IntervalArray.from_strings(data=data, dtype=dtype, closed=closed) | ||
|
||
return cls._simple_new(arr, name=name) | ||
|
||
# -------------------------------------------------------------------- | ||
|
||
@cache_readonly | ||
|
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.
why is this public? shouldn't this be
_from_sequence_of_strings
?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.
Fixed in 40af75d.
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.
Uuuh, changing that name went out of my depth a little... Apparently there are more meanings to that name? Now tests are failing in
pandas/tests/extension/test_interval.py
with testing EA types (I don't know what that means). What's the best way forward here??