-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
ENH: make "closed" part of IntervalDtype #38394
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 1 commit
747926e
25d5925
15613e6
7bd2db6
10c0225
2a82a78
1b93617
f2bb5a1
ded6c31
9816690
aae7d84
b262bdc
c2efb79
5ef58db
bf86746
70c7de6
517c8f1
922ce1a
82ee698
e783761
6e47156
367feee
b10b0bf
370a843
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
Union, | ||
cast, | ||
) | ||
import warnings | ||
|
||
import numpy as np | ||
import pytz | ||
|
@@ -1048,12 +1049,20 @@ def __new__(cls, subtype=None, closed: Optional[str_type] = None): | |
if m is not None: | ||
gd = m.groupdict() | ||
subtype = gd["subtype"] | ||
if "closed" in gd: | ||
if gd.get("closed", None) is not None: | ||
closed = gd["closed"] | ||
elif closed is not None: | ||
# user passed eg. IntervalDtype("interval[int64]", "left") | ||
pass | ||
else: | ||
warnings.warn( | ||
"Constructing an IntervalDtype from a string without " | ||
"specifying 'closed' is deprecated and will raise in " | ||
"a future version. " | ||
f"Use e.g. 'interval[{subtype}, left]'. " | ||
"Defaulting to closed='right'.", | ||
FutureWarning, | ||
) | ||
# default to "right" | ||
closed = "right" | ||
|
||
|
@@ -1070,7 +1079,17 @@ def __new__(cls, subtype=None, closed: Optional[str_type] = None): | |
) | ||
raise TypeError(msg) | ||
|
||
closed = closed or "right" | ||
if closed is None and subtype is not None: | ||
warnings.warn( | ||
"Constructing an IntervalDtype without " | ||
"specifying 'closed' is deprecated and will raise in " | ||
"a future version. " | ||
"Use e.g. IntervalDtype(np.int64, 'left'). " | ||
"Defaulting to closed='right'.", | ||
FutureWarning, | ||
) | ||
closed = "right" | ||
|
||
key = str(subtype) + str(closed) | ||
try: | ||
return cls._cache[key] | ||
|
@@ -1162,6 +1181,13 @@ def __setstate__(self, state): | |
self._subtype = state["subtype"] | ||
# backward-compat older pickles won't have "closed" key | ||
self._closed = state.pop("closed", None) | ||
if self._closed is None: | ||
warnings.warn( | ||
"Unpickled legacy IntervalDtype does not specify 'closed' " | ||
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. test for this? 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. Yes, we have tests for all of the newly-added warning/raising cases in the IntervalDtype constructor. (just added a missing consistency check https://github.com/pandas-dev/pandas/pull/38394/files#diff-f99ef42afad339d00e36197a60ccc76d74c6a94c30e05aef69d18e0ec4b10d4eR1055) 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. woops, dont have a test for this one. will update. 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. huh, this is definitely reached, but tm.assert_produces_warning isnt seeing anything |
||
"attribute. Set dtype._closed to one of 'left', 'right', 'both', " | ||
"'neither' before using this IntervalDtype object.", | ||
UserWarning, | ||
) | ||
|
||
@classmethod | ||
def is_dtype(cls, dtype: object) -> bool: | ||
|
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.
if we have this one do we need to warn on L1058? (e.g. which one is getting hit)
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.
can you respond to this
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.
they are both hit separately