Skip to content

Commit 7106b2b

Browse files
committed
precompile regex
1 parent bd4c893 commit 7106b2b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pandas/io/excel/_odfreader.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828

2929
from pandas._libs.tslibs.nattype import NaTType
3030

31+
# ODF variant of ISO 8601 time/duration format: "PThhhHmmMss.sssS"
32+
# see https://www.w3.org/TR/xmlschema-2/#duration for details
33+
ODF_ISOTIME_PATTERN = re.compile(
34+
r"^\s*PT\s*(\d+)\s*H\s*(\d+)\s*M\s*(\d+)(\.(\d+))?\s*S$"
35+
)
36+
3137

3238
@doc(storage_options=_shared_docs["storage_options"])
3339
class ODFReader(BaseExcelReader["OpenDocument"]):
@@ -186,10 +192,9 @@ def _get_column_repeat(self, cell) -> int:
186192

187193
def _parse_odf_time(self, value: str) -> datetime.time:
188194
"""
189-
Helper function to convert ODF variant of ISO 8601 formatted duration
190-
"PnYnMnDTnHnMnS" - see https://www.w3.org/TR/xmlschema-2/#duration
195+
This helper function parses ODF time value
191196
"""
192-
parts = re.match(r"^\s*PT\s*(\d+)\s*H\s*(\d+)\s*M\s*(\d+(\.\d+)?)\s*S$", value)
197+
parts = ODF_ISOTIME_PATTERN.match(value)
193198
if parts is None:
194199
raise ValueError(f"Failed to parse ODF time value: {value}")
195200
hours, minutes, seconds, _, second_part = parts.group(*range(1, 6))

0 commit comments

Comments
 (0)