Skip to content

Commit 306095e

Browse files
authored
Merge pull request #219 from scottshambaugh/build_error
Fix build error
2 parents 6e901fa + 0ebd041 commit 306095e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Diff for: labellines/core.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,22 @@ def labelLines(
283283
else:
284284
converter = ax.xaxis.get_converter()
285285
time_classes = (_SwitchableDateConverter, DateConverter, ConciseDateConverter)
286-
if isinstance(converter, time_classes):
287-
xvals = [
288-
num2date(x).replace(tzinfo=ax.xaxis.get_units())
289-
for x in xvals # type: ignore
290-
]
286+
if xvals is None:
287+
raise ValueError(
288+
"xvals must be a tuple of two floats or a list of floats."
289+
f"Got {xvals} instead."
290+
)
291+
elif isinstance(converter, time_classes):
292+
xvals_dates = []
293+
for x in xvals:
294+
if isinstance(x, datetime):
295+
x_datetime = x
296+
elif isinstance(x, np.datetime64):
297+
x_datetime = x.astype(datetime)
298+
else:
299+
x_datetime = num2date(x)
300+
xvals_dates.append(x_datetime.replace(tzinfo=ax.xaxis.get_units()))
301+
xvals = xvals_dates
291302

292303
txts = []
293304
try:

0 commit comments

Comments
 (0)