When I'm running rolling() with swifter like below, I get a runtime error "init() got an unexpected keyword argument 'axis'".
import numpy as np
import pandas as pd
import swifter
t = np.arange("1900年01月01日", "2019年12月25日", dtype=np.datetime64)
np.random.seed(seed=0)
y = np.random.rand(len(t))
df_pd = pd.DataFrame({"t": t, "y": y})
df_pd.head()
df_pd.swifter.set_npartitions(npartitions=8).progress_bar(True).rolling(5).apply(np.mean)
pandas version 2.2.2
swifter version 1.4.0
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\program files\microsoft visual studio2022円\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\program files\microsoft visual studio2022円\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\program files\microsoft visual studio2022円\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\program files\microsoft visual studio2022円\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File "c:\program files\microsoft visual studio2022円\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\program files\microsoft visual studio2022円\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Users\owner\source\repos\PythonApplication7\PythonApplication7\PythonApplication7.py", line 27, in <module>
df_pd.swifter.set_npartitions(npartitions=8).progress_bar(True).rolling(5).apply(np.mean)
File "C:\Users\owner\AppData\Roaming\Python\Python39\site-packages\swifter\swifter.py", line 162, in rolling
return Rolling(
File "C:\Users\owner\AppData\Roaming\Python\Python39\site-packages\swifter\swifter.py", line 737, in __init__
self._obj_dd = self._obj_dd.rolling(**{k: v for k, v in kwds.items() if k not in ["on", "closed"]})
File "C:\Users\owner\AppData\Roaming\Python\Python39\site-packages\dask_expr\_collection.py", line 974, in rolling
return Rolling(self, window, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'axis'
1 Answer 1
This seems to be a problem in the swifter source code. At present, swifter.rolling passes an "axis" kwarg to its Dask counterpart. This kwarg is no longer valid in the Dask implementation, as it was deprecated with pandas>=2.1, so any call to swifter.rolling is guaranteed to raise an error.
I don't know of any proper workaround at present, though I've opened an issue on GitHub.
answered Sep 2, 2024 at 7:17
Anerdw
2,8583 gold badges18 silver badges44 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py