【问题标题】:SQL Server Python INTERNAL ERROR: should have tagSQL Server Python 内部错误:应该有标签
【发布时间】:2020-12-06 22:36:23
【问题描述】:

我正在尝试使用 python 将 SQL Server 2017 或 2019 与 Qunatlib 集成。我可以运行 Quantlib 代码,在这种特殊情况下,它返回一个 Qunatlib 调度对象,它是一个 Quantlib.Date 类型的枚举列表。代码是这样的

EXECUTE sp_execute_external_script
  @language = N'Python',
  @script = N'
import QuantLib as QL
import pandas as PD

effective_date = QL.Date(1, 1, 2015)
termination_date = QL.Date(1, 1, 2016)
tenor = QL.Period(QL.Monthly)
calendar = QL.UnitedStates()
business_convention = QL.Following
termination_business_convention = QL.Following
date_generation = QL.DateGeneration.Forward
end_of_month = False

schedule = QL.Schedule(effective_date,termination_date,tenor,calendar,business_convention,termination_business_convention,date_generation,end_of_month)
OutputDataSet  = PD.DataFrame(list(enumerate(schedule)),  columns=[''index'',''RollDate''])'

但是我得到以下错误

INTERNAL ERROR: should have tag
error while running BxlServer: caught exception: Error communicating between BxlServer and client: 0x000000e9

如果我删除最后一行

OutputDataSet  = PD.DataFrame(list(enumerate(schedule)),  columns=[''index'',''RollDate''])'

脚本运行没有错误。我也可以在其他 python 环境中运行脚本而不会出错。我怀疑这个问题与数据转换有关,但该错误并不是特别有用。我需要将数据放入数据框中,以便在 SQL Server 中使用。

【问题讨论】:

    标签: python sql-server pandas quantlib microsoft-machine-learning-server


    【解决方案1】:

    解决了。需要将数据类型转换为日期时间并将其添加到熊猫中。

    import QuantLib as QL
    import pandas as PD
    import datetime
    
    effective_date = QL.Date(1, 1, 2015)
    termination_date = QL.Date(1, 1, 2016)
    tenor = QL.Period(QL.Monthly)
    calendar = QL.UnitedStates()
    business_convention = QL.Following
    termination_business_convention = QL.Following
    date_generation = QL.DateGeneration.Forward
    end_of_month = False
    
    schedule = QL.Schedule(effective_date,termination_date,tenor,calendar,business_convention,termination_business_convention,date_generation,end_of_month)
    
    OutputDataSet=PD.DataFrame(columns=[''RollDate''])
    for i, d in enumerate(schedule):
        OutputDataSet.loc[i]=datetime.datetime(d.year(), d.month(), d.dayOfMonth())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-10
      • 1970-01-01
      • 2010-12-31
      • 2010-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-26
      相关资源
      最近更新 更多