Skip to content

Commit

Permalink
owcsvimport: Add explicit to_datetime conversion
Browse files Browse the repository at this point in the history
On newer pandas (dev) read_csv leaves `parse_dates` columns which
failed (strict) parsing as object columns. Add explicit to_datetime
coercion when that happens.
  • Loading branch information
ales-erjavec committed Jan 5, 2024
1 parent 3a7bc6c commit 0bed791
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Orange/widgets/data/owcsvimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,12 @@ def expand(ranges):
na_values=na_values, keep_default_na=False,
**numbers_format_kwds
)

if parse_dates:
for date_col in parse_dates:
if df.dtypes[date_col] == "object":
df[df.columns[date_col]] = pd.to_datetime(

Check warning on line 1560 in Orange/widgets/data/owcsvimport.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/data/owcsvimport.py#L1560

Added line #L1560 was not covered by tests
df.iloc[:, date_col], errors="coerce"
)
if prefix:
df.columns = [f"{prefix}{column}" for column in df.columns]

Expand Down

0 comments on commit 0bed791

Please sign in to comment.