Spaces:
Running
Running
Capture Nones gracefully in historical date parsing.
Browse files- timebench_eval.py +5 -3
timebench_eval.py
CHANGED
|
@@ -263,16 +263,18 @@ class TimebenchEval(evaluate.Metric):
|
|
| 263 |
return {"exact_match": exact_matches, "f1": f1_scores}
|
| 264 |
|
| 265 |
@staticmethod
|
| 266 |
-
def _parse_historical_date(date_str: str) -> datetime | None:
|
| 267 |
"""
|
| 268 |
Parse a date string and return a datetime object with day set to 1.
|
| 269 |
|
| 270 |
Args:
|
| 271 |
-
date_str: String representation of a date.
|
| 272 |
|
| 273 |
Returns:
|
| 274 |
-
datetime object with day set to 1, or None if parsing fails.
|
| 275 |
"""
|
|
|
|
|
|
|
| 276 |
try:
|
| 277 |
return parser.parse(date_str).replace(day=1)
|
| 278 |
except ParserError:
|
|
|
|
| 263 |
return {"exact_match": exact_matches, "f1": f1_scores}
|
| 264 |
|
| 265 |
@staticmethod
|
| 266 |
+
def _parse_historical_date(date_str: str | None) -> datetime | None:
|
| 267 |
"""
|
| 268 |
Parse a date string and return a datetime object with day set to 1.
|
| 269 |
|
| 270 |
Args:
|
| 271 |
+
date_str: String representation of a date, or None.
|
| 272 |
|
| 273 |
Returns:
|
| 274 |
+
datetime object with day set to 1, or None if parsing fails or input is None.
|
| 275 |
"""
|
| 276 |
+
if date_str is None:
|
| 277 |
+
return None
|
| 278 |
try:
|
| 279 |
return parser.parse(date_str).replace(day=1)
|
| 280 |
except ParserError:
|