limit type to 32
This commit is contained in:
parent
8095a260b7
commit
b2791836a4
@ -136,18 +136,18 @@ def reduce_mem_usage(pair: str, df: DataFrame) -> DataFrame:
|
|||||||
c_min = df[col].min()
|
c_min = df[col].min()
|
||||||
c_max = df[col].max()
|
c_max = df[col].max()
|
||||||
if str(col_type)[:3] == "int":
|
if str(col_type)[:3] == "int":
|
||||||
if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:
|
# if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:
|
||||||
df[col] = df[col].astype(np.int8)
|
# df[col] = df[col].astype(np.int8)
|
||||||
elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:
|
# elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:
|
||||||
df[col] = df[col].astype(np.int16)
|
# df[col] = df[col].astype(np.int16)
|
||||||
elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:
|
if c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:
|
||||||
df[col] = df[col].astype(np.int32)
|
df[col] = df[col].astype(np.int32)
|
||||||
elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:
|
elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:
|
||||||
df[col] = df[col].astype(np.int64)
|
df[col] = df[col].astype(np.int64)
|
||||||
elif str(col_type)[:5] == "float":
|
elif str(col_type)[:5] == "float":
|
||||||
if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:
|
# if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:
|
||||||
df[col] = df[col].astype(np.float16)
|
# df[col] = df[col].astype(np.float16)
|
||||||
elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:
|
if c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:
|
||||||
df[col] = df[col].astype(np.float32)
|
df[col] = df[col].astype(np.float32)
|
||||||
else:
|
else:
|
||||||
df[col] = df[col].astype(np.float64)
|
df[col] = df[col].astype(np.float64)
|
||||||
|
Loading…
Reference in New Issue
Block a user