Skip to content

Commit 3620bfe

Browse files
committed
Fixes
1 parent 1979ca8 commit 3620bfe

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

label_studio_ml/examples/timeseries_segmenter/model.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,36 @@ def _collect_samples(
269269
end = r["value"]["end"]
270270
label = r["value"]["timeserieslabels"][0]
271271

272+
# Convert start/end to same type as time column for comparison
273+
time_dtype = df[params["time_col"]].dtype
274+
logger.debug(f"Task {task_id}: Converting time range [{start}, {end}] to match column dtype {time_dtype}")
275+
try:
276+
if 'int' in str(time_dtype):
277+
start = int(float(start))
278+
end = int(float(end))
279+
elif 'float' in str(time_dtype):
280+
start = float(start)
281+
end = float(end)
282+
# For string/datetime, keep as is
283+
logger.debug(f"Task {task_id}: Converted to [{start}, {end}]")
284+
except (ValueError, TypeError) as e:
285+
logger.warning(f"Could not convert start={start}, end={end} to {time_dtype}: {e}, using original values")
286+
272287
# Find rows in this time range
273-
mask = (df[params["time_col"]] >= start) & (
274-
df[params["time_col"]] <= end
275-
)
288+
try:
289+
mask = (df[params["time_col"]] >= start) & (
290+
df[params["time_col"]] <= end
291+
)
292+
except TypeError as e:
293+
logger.error(f"Task {task_id}: Type error comparing times - start={start} ({type(start)}), end={end} ({type(end)}), time_col dtype={time_dtype}: {e}")
294+
# Skip this annotation if we can't compare
295+
continue
276296

277297
# Set the appropriate label index
278298
label_idx = label2idx[label]
279299
row_labels[mask] = label_idx
280300
labeled_rows += mask.sum()
301+
logger.debug(f"Task {task_id}: Labeled {mask.sum()} rows with '{label}' (index {label_idx})")
281302

282303
# Add ALL rows to training data
283304
X_list.append(df[params["channels"]].values.astype(np.float32))

label_studio_ml/examples/timeseries_segmenter/tests/test_segmenter.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ def segmenter_instance(temp_model_dir):
7474
logger.info("Creating TimeSeriesSegmenter instance for testing")
7575
with patch.dict(os.environ, {'MODEL_DIR': temp_model_dir, 'TRAIN_EPOCHS': '10', 'SEQUENCE_SIZE': '10'}):
7676
segmenter = TimeSeriesSegmenter(
77-
label_config=LABEL_CONFIG,
78-
parsed_label_config={},
79-
train_output={}
77+
label_config=LABEL_CONFIG
8078
)
8179
segmenter.setup()
8280
logger.info("TimeSeriesSegmenter instance created and set up")
@@ -472,9 +470,7 @@ def test_model_parameters_configuration(self, temp_model_dir):
472470
logger.info(f"Testing configuration {i+1}/{len(configs)}: {config}")
473471
with patch.dict(os.environ, {**config, 'MODEL_DIR': temp_model_dir}):
474472
segmenter = TimeSeriesSegmenter(
475-
label_config=LABEL_CONFIG,
476-
parsed_label_config={},
477-
train_output={}
473+
label_config=LABEL_CONFIG
478474
)
479475
segmenter.setup()
480476

0 commit comments

Comments
 (0)