Skip to content

[tradingcal] [bugfix] Index.searchsorted() method accepts only pandas timestamps in v1.0 of the library. #18

@vladisld

Description

@vladisld

Description

PandasMarketCalendar class uses the pandas dataframe to cache the trading dates schedule. Unfortunately in schedule method a wrong data type is used to search in this cache in case the pandas library v1.0 is used.

def schedule(self, day, tz=None):
        '''
        Returns the opening and closing times for the given ``day``. If the
        method is called, the assumption is that ``day`` is an actual trading
        day

        The return value is a tuple with 2 components: opentime, closetime
        '''
        while True:
            #### The problem is here #####
            i = self.idcache.index.searchsorted(ay.date())

            if i == len(self.idcache):
                # keep a cache of 1 year to speed up searching
                self.idcache = self._calendar.schedule(day, day + self.csize)
                continue

            st = (x.tz_localize(None) for x in self.idcache.iloc[i, 0:2])
            opening, closing = st  # Get utc naive times
            if day > closing:  # passed time is over the sessionend
                day += ONEDAY  # wrap over to next day
                continue

            return opening.to_pydatetime(), closing.to_pydatetime()

Unexpected behavior

I don't remember exactly whether or not an exception is raised or the search just return empty result

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions