Skip to content

Commit d92805a

Browse files
handle datetime64
1 parent 94ac200 commit d92805a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: labellines/core.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,16 @@ def labelLines(
284284
converter = ax.xaxis.get_converter()
285285
time_classes = (_SwitchableDateConverter, DateConverter, ConciseDateConverter)
286286
if isinstance(converter, time_classes):
287-
xvals = [
288-
x # type: ignore
289-
if isinstance(x, (np.datetime64, datetime))
290-
else num2date(x).replace(tzinfo=ax.xaxis.get_units())
291-
for x in xvals # type: ignore
292-
]
287+
xvals_dates = []
288+
for x in xvals: # type: ignore
289+
if isinstance(x, datetime):
290+
x_datetime = x
291+
elif isinstance(x, np.datetime64):
292+
x_datetime = x.astype(datetime)
293+
else:
294+
x_datetime = num2date(x)
295+
xvals_dates.append(x_datetime.replace(tzinfo=ax.xaxis.get_units()))
296+
xvals = xvals_dates # type: ignore
293297

294298
txts = []
295299
try:

0 commit comments

Comments
 (0)