作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
to_sql()
pandas 中的函数现在正在产生 SADeprecationWarning。df.to_sql(name=tablename, con=c, if_exists='append', index=False )
[..]/lib/python3.8/site-packages/pandas/io/sql.py:1430: SADeprecationWarning:The Connection.run_callable() method is deprecated and will be removed in a future release. Use a context manager instead. (deprecated since: 1.4)
即使使用
df.read_sql()
我也得到了这个命令,在运行 sql select 语句时。改成原来的
df.read_sql_query()
它环绕,摆脱它。我怀疑那里会有一些联系。
conn_str = r'mssql+pyodbc:///?odbc_connect={}'.format(dbString).strip()
sqlEngine = sqlalchemy.create_engine(conn_str,echo=False, pool_recycle=3600)
c = sqlEngine.connect()
而在db操作之后,
c.close()
这样做可以让主连接 sqlEngine 在 api 调用之间保持“事件”状态,并让我使用池连接而不必重新连接。
最佳答案
更新:据 Pandas 团队称,这将在截至撰写本文时尚未发布的 Pandas 1.2.4 中修复。
添加此作为答案,因为谷歌在这里领先,但接受的答案不适用。
我们使用 Pandas 的周围代码确实使用了上下文管理器:
with get_engine(dbname).connect() as conn:
df = pd.read_sql(stmt, conn, **kwargs)
return df
就我而言,这个错误是从 Pandas 本身内部抛出的,而不是在使用 Pandas 的周围代码中:
/Users/tommycarpenter/Development/python-indexapi/.tox/py37/lib/python3.7/site-packages/pandas/io/sql.py:1430: SADeprecationWarning: The Engine.run_callable() method is deprecated and will be removed in a future release. Use the Engine.connect() context manager instead. (deprecated since: 1.4)
Pandas 本身的片段是:
def has_table(self, name, schema=None):
return self.connectable.run_callable(
self.connectable.dialect.has_table, name, schema or self.meta.schema
)
我提出了一个问题:
https://github.com/pandas-dev/pandas/issues/40825
关于python - pandas to_sql() 给出了 SADeprecationWarning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66680224/
to_sql() pandas 中的函数现在正在产生 SADeprecationWarning。df.to_sql(name=tablename, con=c, if_exists='append',
我是一名优秀的程序员,十分优秀!