utils.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:stream2segment 作者: rizac 项目源码 文件源码
def handledbexc(cols_to_print_on_err, update=False):
    """Returns a **function** to be passed to pdsql functions when inserting/ updating
    the db. Basically, it prints to log"""
    if not cols_to_print_on_err:
        return None

    def hde(dataframe, exception):
        if not empty(dataframe):
            try:
                # if sql-alchemy exception, try to guess the orig atrribute which represents
                # the wrapped exception
                # http://docs.sqlalchemy.org/en/latest/core/exceptions.html
                errmsg = str(exception.orig)
            except AttributeError:
                # just use the string representation of exception
                errmsg = str(exception)
            len_df = len(dataframe)
            msg = MSG("%d database rows not %s" % (len_df, "updated" if update else "inserted"),
                      errmsg)
            logwarn_dataframe(dataframe, msg, cols_to_print_on_err)
    return hde
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号