如何修复 DatetimeIndex.union_many 已弃用 Python 中的警告

How to fix DatetimeIndex.union_many is deprecated warning in Python

我有以下代码:

import datetime, pytz
import pandas_market_calendars as mcal

today_date = datetime.datetime.now(tz=pytz.timezone('US/Eastern'))
start_date = datetime.date(today_date.year - 5, today_date.month, today_date.day)

end_date = datetime.date(today_date.year + 2, today_date.month, today_date.day + 5)

nyse_calender = mcal.get_calendar('NYSE')
nyse_business_days = nyse_calender.schedule(start_date=start_date, end_date=end_date)

当我 运行 这样做时,我收到以下警告:

 FutureWarning: DatetimeIndex.union_many is deprecated and will be removed in a future version. Use obj.union instead.   
  nyse_business_days = nyse_calender.schedule(start_date=start_date, end_date=end_date)

我该如何解决这个问题?警告并不能真正帮助采取行动..

我遇到了同样的问题,刚准备养我的时候看到这个。在这里,我提供了更多调试细节:

pandas version 1.4.0

pandas_market_calendars version 3.3(it also happens on version3.2)

警告来自行:

    nyse_business_days = nyse_calender.schedule(start_date=start_date, end_date=end_date)

我对pandas_market_calendars进行了进一步的调试,它实际上来自market_calendar.py第514行,看起来像:

        for market_time in market_times:
            temp = self.days_at_time(_all_days, market_time) # standard times
            if _adj_col:
                # mark here, according with Yunfei's debugging, it orients from here
                # create an array of special times
                special = self.special_dates(market_time, start_date, end_date, filter_holidays= False)

在我这边,函数的输入是这样的:

market_time
'market_open'
start_date
Timestamp('2021-07-05 00:00:00')
end_date
Timestamp('2021-07-25 00:00:00')

由于第 514 行实际上 运行 来自循环,我的控制台显示了数千个这样的 'futurewarning',求救

几天前合并了 pandas_market_calendarPR,解决了这个问题。