From 83aaf207d6c8d566b697810d3f14697f8df9b37b Mon Sep 17 00:00:00 2001 From: Helge Hatteland Date: Wed, 6 Apr 2022 15:25:21 +0200 Subject: [PATCH 1/2] Allow using datetime64[ns, UTC] in IntervalDtype The current regexp doesn't allow the use of comma in the interval `subtype`, which means this statement fails ``` pd.IntervalIndex.from_arrays([1, 2], [2, 3], dtype='interval[datetime64[ns, UTC], right]') ``` with `TypeError: data type 'interval[datetime64[ns, UTC], right]' not understood` The proposed change allows the use of comma inside square brackets in the `subtype`. --- pandas/core/dtypes/dtypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 58e91f46dff43..da9826ea4ad2d 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -1054,7 +1054,7 @@ class IntervalDtype(PandasExtensionDtype): "closed", ) _match = re.compile( - r"(I|i)nterval\[(?P[^,]+)(, (?P(right|left|both|neither)))?\]" + r"(I|i)nterval\[(?P[^,]+(\[.+\])?)(, (?P(right|left|both|neither)))?\]" ) _cache_dtypes: dict[str_type, PandasExtensionDtype] = {} From 6a918124b705da72ac92be3a10bf07f6322adbbc Mon Sep 17 00:00:00 2001 From: Helge Hatteland Date: Wed, 6 Apr 2022 15:36:59 +0200 Subject: [PATCH 2/2] Split regexp into two lines --- pandas/core/dtypes/dtypes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index da9826ea4ad2d..70b1f8a4b18e3 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -1054,7 +1054,8 @@ class IntervalDtype(PandasExtensionDtype): "closed", ) _match = re.compile( - r"(I|i)nterval\[(?P[^,]+(\[.+\])?)(, (?P(right|left|both|neither)))?\]" + r"(I|i)nterval\[(?P[^,]+(\[.+\])?)" + r"(, (?P(right|left|both|neither)))?\]" ) _cache_dtypes: dict[str_type, PandasExtensionDtype] = {}