Skip to content

Commit ec6dc1f

Browse files
authored
Add warning for implicit float conversion (#1221)
1 parent 5dd395a commit ec6dc1f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

awswrangler/_data_types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44
import logging
55
import re
6+
import warnings
67
from decimal import Decimal
78
from typing import Any, Callable, Dict, Iterator, List, Match, Optional, Sequence, Tuple, Union
89

@@ -661,6 +662,12 @@ def _cast_pandas_column(df: pd.DataFrame, col: str, current_type: str, desired_t
661662
_logger.debug("Column: %s", col)
662663
if "object cannot be converted to an IntegerDtype" not in str(ex):
663664
raise ex
665+
warnings.warn(
666+
"Object cannot be converted to an IntegerDtype. Integer columns in Python cannot contain "
667+
"missing values. If your input data contains missing values, it will be encoded as floats"
668+
"which may cause precision loss.",
669+
UserWarning,
670+
)
664671
df[col] = (
665672
df[col]
666673
.apply(lambda x: int(x) if str(x) not in ("", "none", "None", " ", "<NA>") else None)

0 commit comments

Comments
 (0)