sunnyportal-py
sunnyportal-py copied to clipboard
Cannot losslessly cast from float64 to uint32
Hi, when downloading the data of 2021 i get the following error.
./bin/sunnyportal2file:127: FutureWarning: Passing unit-less datetime64 dtype to .astype is deprecated and will raise in a future version. Pass 'datetime64[ns]' instead
self._new_df = df.astype({k: self._dtype_dict[k] for k in df.columns})
Traceback (most recent call last):
File "/mnt/c/Users/u16v02/source/sunnyportal-py/./bin/sunnyportal2file", line 427, in <module>
main()
File "/mnt/c/Users/u16v02/source/sunnyportal-py/./bin/sunnyportal2file", line 415, in main
df_handler.download_new_data()
File "/mnt/c/Users/u16v02/source/sunnyportal-py/./bin/sunnyportal2file", line 127, in download_new_data
self._new_df = df.astype({k: self._dtype_dict[k] for k in df.columns})
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/generic.py", line 6226, in astype
res_col = col.astype(dtype=cdt, copy=copy, errors=errors)
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/generic.py", line 6240, in astype
new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 445, in astype
return self.apply("astype", dtype=dtype, copy=copy, errors=errors)
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 347, in apply
applied = getattr(b, f)(**kwargs)
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/internals/blocks.py", line 526, in astype
new_values = astype_array_safe(values, dtype, copy=copy, errors=errors)
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/dtypes/astype.py", line 299, in astype_array_safe
new_values = astype_array(values, dtype, copy=copy)
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/dtypes/astype.py", line 230, in astype_array
values = astype_nansafe(values, dtype, copy=copy)
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/dtypes/astype.py", line 140, in astype_nansafe
return _astype_float_to_int_nansafe(arr, dtype, copy)
File "/home/cornelius/.local/lib/python3.10/site-packages/pandas/core/dtypes/astype.py", line 188, in _astype_float_to_int_nansafe
raise ValueError(f"Cannot losslessly cast from {values.dtype} to {dtype}")
ValueError: Cannot losslessly cast from float64 to uint32
Hmm. Downgrading pandas to version 1.3.5 solved the issue.
How can I reproduce the error? Which flags/what fomat did you choose? Was this during merging of new data or during initial download?
The sunnyportal API has been shut down.