简体   繁体   English

在python中使用business_calendar时的警告信息

[英]Warning message when using business_calendar in python

I would like to use the business_calendar function in python.我想在 python 中使用 business_calendar 函数。 I have a list of public holidays I would like to add to my calendar.我有一个公共假期列表,我想添加到我的日历中。 I have followed the example code in creating my calendar, here is my code:我在创建日历时遵循了示例代码,这是我的代码:

from business_calendar import Calendar, MO, TU, WE, TH, FR
import datetime
date1 = datetime.datetime(2017,9,22)
cal = Calendar(holidays=list([datetime.datetime(2017,9,25),datetime.datetime(2017,9,28)]))
date2 = (cal.addbusdays(date1, 3))
print (date2)

The function seems to be working correctly, however I am concerned about the warning message that is displayed:该功能似乎工作正常,但我担心显示的警告消息:

C:\Program Files\WinPython-64bit-3.5.2.3\python-3.5.2.amd64\lib\site-packages\spyder\utils\ipython\start_kernel.py:5: CalendarHolidayWarning: Holiday list exhausted at end, addbusday(2017-09-22 00:00:00,3) output may be incorrect. # (see spyder/__init__.py for details)

I have attempted to find out how to resolve this, but have had no luck.我试图找出如何解决这个问题,但没有运气。 Any assistance would be appreciated.任何援助将不胜感激。

Thank you谢谢

It's giving you this warning because it has reached the last holiday in your list, and has no way of knowing how far into the future that list covers. 之所以会发出警告,是因为它已到达列表中的最后一个假期,并且无法知道列表涵盖的时间有多远。 Specifically, it has no way of knowing whether the 29th is a holiday or not. 具体来说,它无法知道29日是否是假期。 Adding a holiday far in the future, or having the whole year's holidays in the list (which is probably the normal use-case for this module), would avoid the warning. 在将来增加一个假期,或在列表中包含全年的假期(这可能是此模块的正常用例),可以避免该警告。

In case someone is wondering.万一有人想知道。 The list may be exahusted because the remaining holidays are in a non-working days.由于剩余假期在非工作日内,因此列表可能会变多。 So basically you can add few artificial holidays on 29,30,31.12 or around asian new year, if this is the case :) Or you may just ignore the message.所以基本上你可以在 29,30,31.12 或亚洲新年前后添加一些人工假期,如果是这种情况:) 或者你可以忽略该消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM