yun*_*fei 6 python concatenation keyword-argument pandas future-warning
有人遇到过类似的吗FutureWarning?我在使用Tiingo+pandas_datareader时得到这个?
警告就像:
python3.8/site-packages/pandas_datareader/tiingo.py:234: FutureWarning: In a future version of pandas all arguments of concat except for the argument 'objs' will be keyword-only
return pd.concat(dfs, self._concat_axis)
Run Code Online (Sandbox Code Playgroud)
我认为这个警告不会影响我对 pandas 数据的访问(在我的例子中,我从 tiingo api 获取),我可以毫无问题地获取我想要的所有数据。我只是想了解我当前的环境是否存在任何风险:
my python3 - 3.8.5,
Python 3.8.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
pandas_datareader version - 0.10.0
pandas version - 1.3.2
Run Code Online (Sandbox Code Playgroud)
然后我用 python 的“futureVersion”测试了我的代码:3.9.6(与 python 3.8.5 相比)。令我惊讶的是,我不再收到任何警告或错误,一切正常:
以下是更新的详细信息
platform win32
- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏。
Ale*_*ood 14
即如果我有这个功能:
\ndef do_something(x, y):\n pass\nRun Code Online (Sandbox Code Playgroud)\n然后我可以使用位置参数这样调用它:
\ndo_something(1, 2)\nRun Code Online (Sandbox Code Playgroud)\n或者像这样,使用关键字参数:
\ndo_something(x=1, y=2)\nRun Code Online (Sandbox Code Playgroud)\n或者像这样,使用两者的混合(但请注意,不允许在关键字参数之后有位置参数):
\ndo_something(1, y=2)\nRun Code Online (Sandbox Code Playgroud)\n假设我有这个其他功能:
\ndef do_something_else(x, /, y, *, z):\n pass\nRun Code Online (Sandbox Code Playgroud)\n在此函数中,我已将其标记x为仅限位置,因为它位于/. 我已将其标记z为仅限关键字,因为它位于*. y是一个位置或关键字参数,因为它位于 后面/但之前*。这意味着调用该函数的这两次尝试都会失败:第一个是因为z被作为位置参数调用,第二个是因为x被作为关键字参数调用:
do_something_else(1, 2, 3) # will fail!\ndo_something_else(x=1, y=2, z=3) # will fail!\nRun Code Online (Sandbox Code Playgroud)\n然而,这两次尝试都会成功 \xe2\x80\x94y仍然是位置或关键字参数。
do_something_else(1, 2, z=3) # fine\ndo_something_else(1, y=2, z=3) # fine\nRun Code Online (Sandbox Code Playgroud)\n该FutureWarning消息与您正在使用的 python 版本无关,但与pandas您正在使用的 python 版本有关。Pandas是第三方库,不是 python 核心的一部分,因此pandas您正在使用的版本与您正在使用的 python 版本完全不同。
该警告让您知道,目前您可以编写pd.concat(dfs, self._concat_axis),但他们计划在 的未来版本中更改函数的定义pandas,以便除 for 之外的所有参数都objs将仅是关键字。即,在他们进行此更改后,pd.concat(dfs, self._concat_axis)将引发错误,并且您必须改为编写pd.concat(dfs, axis=self._concat_axis)。他们很可能考虑进行此更改,因为使用关键字参数调用函数对于其他人来说通常更清晰且更具可读性。
| 归档时间: |
|
| 查看次数: |
16038 次 |
| 最近记录: |