Skip to content

Commit 5f65c92

Browse files
committed
plotting: fix string based sequence column detection
1 parent 740954b commit 5f65c92

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

spinetoolbox/plotting.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,17 @@ class ParameterTableHeaderSection:
116116

117117
# Regex pattern to indentify numerical sequences encoded as string
118118
SEQ_PAT = re.compile(r"^([a-zA-Z])([0-9]+)$")
119+
STR_TYPES = (
120+
object,
121+
pd.StringDtype(na_value=pd.NA),
122+
pd.StringDtype(na_value=np.nan),
123+
)
119124

120125

121126
def parse_time(df: pd.DataFrame) -> pd.DataFrame:
122127
"""Parse 'time' or 'period' columns to integers for plotting."""
123128
for col, _type in df.dtypes.items():
124-
if _type in (object, pd.StringDtype()) and (groups := df[col].str.extract(SEQ_PAT)).notna().all(axis=None):
129+
if _type in STR_TYPES and (groups := df[col].str.extract(SEQ_PAT)).notna().all(axis=None):
125130
df[col] = groups[1].astype(int)
126131
return df
127132

0 commit comments

Comments
 (0)