Skip to content

Commit

Permalink
Datetime loading fix (#10)
Browse files Browse the repository at this point in the history
* Fix dataset loading

* Add catch if format isn't day-first
  • Loading branch information
hamishteagle authored Mar 13, 2024
1 parent 84e3c0b commit 773c556
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/synthesized_datasets/_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ def load(self) -> _pd.DataFrame:
df = _pd.read_csv(self.url, dtype=dtypes)
for col, dtype in self._schema.items():
if dtype in [_DType.DATETIME, _DType.DATE]:
df[col] = _pd.to_datetime(df[col], dayfirst=True)
try:
df[col] = _pd.to_datetime(df[col])
except ValueError:
df[col] = _pd.to_datetime(df[col], dayfirst=True)
if dtype in [_DType.TIMEDELTA, _DType.TIME]:
df[col] = _pd.to_timedelta(df[col])
df.attrs["name"] = self.name
Expand Down

0 comments on commit 773c556

Please sign in to comment.