Skip to content

Commit 86b3799

Browse files
raise error for string indices in dataframes passed to is_regular
1 parent c42752c commit 86b3799

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

vtools/data/timeseries.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -551,19 +551,7 @@ def is_regular(ts, raise_exception=False):
551551

552552
# If index is string-like, try datetime first, then numeric.
553553
if pd.api.types.is_string_dtype(idx.dtype):
554-
dt_idx = pd.to_datetime(idx, errors="coerce")
555-
if not dt_idx.isna().any():
556-
idx = pd.DatetimeIndex(dt_idx)
557-
else:
558-
num = pd.to_numeric(idx, errors="coerce")
559-
if np.isnan(num).any():
560-
msg = (
561-
"Index is a string that can't convert to datetime or numeric - can't assess regularity."
562-
)
563-
if raise_exception:
564-
raise ValueError(msg)
565-
return False
566-
idx = pd.Index(num)
554+
raise ValueError("String indices are not supported for regularity checks.")
567555

568556
# Handle numeric indices (int, float)
569557
if isinstance(idx, (pd.Index, pd.RangeIndex)) and pd.api.types.is_numeric_dtype(idx.dtype):

0 commit comments

Comments
 (0)