Skip to content

Commit

Permalink
fix: suppress warnings in data type inference (#179)
Browse files Browse the repository at this point in the history
Pandas 2.0 `pd.to_datetime` warns upon unsuccessful inference of date
format.
The warning is unwanted since we use the success/failure of conversion
to datetime to determine
whether a column is a datetime, i.e. knowingly call the function on data
which might not contain
datetimes.
  • Loading branch information
mbelak-dtml authored Oct 13, 2023
1 parent 9b5cf70 commit ef16b3b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion edvart/data_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from enum import IntEnum

import numpy as np
Expand Down Expand Up @@ -179,7 +180,9 @@ def is_date(series: pd.Series) -> bool:
if contains_numerics:
return False
try:
converted_series = pd.to_datetime(series.dropna(), errors="coerce")
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
converted_series = pd.to_datetime(series.dropna(), errors="coerce")
except ValueError:
return False
return converted_series.notna().all()
1 change: 1 addition & 0 deletions edvart/report_sections/dataset_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def required_imports(self) -> List[str]:
"from enum import IntEnum",
"import numpy as np",
"from IPython.display import display",
"import warnings",
]

def add_cells(self, cells: List[Dict[str, Any]], df: pd.DataFrame) -> None:
Expand Down

0 comments on commit ef16b3b

Please sign in to comment.