Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with latest version of Pandas #40

Closed
DePasqualeOrg opened this issue Jul 4, 2021 · 3 comments · Fixed by #41
Closed

Error with latest version of Pandas #40

DePasqualeOrg opened this issue Jul 4, 2021 · 3 comments · Fixed by #41

Comments

@DePasqualeOrg
Copy link

I recently updated my packages, and now when calling from exchange_calendars import get_calendar, I get the following error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from exchange_calendars import get_calendar
  File "/opt/miniconda3/lib/python3.7/site-packages/exchange_calendars/__init__.py", line 16, in <module>
    from .calendar_utils import (
  File "/opt/miniconda3/lib/python3.7/site-packages/exchange_calendars/calendar_utils.py", line 3, in <module>
    from .always_open import AlwaysOpenCalendar
  File "/opt/miniconda3/lib/python3.7/site-packages/exchange_calendars/always_open.py", line 5, in <module>
    from .exchange_calendar import ExchangeCalendar
  File "/opt/miniconda3/lib/python3.7/site-packages/exchange_calendars/exchange_calendar.py", line 27, in <module>
    from .calendar_helpers import (
  File "/opt/miniconda3/lib/python3.7/site-packages/exchange_calendars/calendar_helpers.py", line 6, in <module>
    NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType'

This occurs both on macOS with Python 3.7 and Ubuntu with Python 3.8.

@DePasqualeOrg
Copy link
Author

The issue seems to have been introduced with the latest version of Pandas (1.3.0). After downgrading to the previous version (1.2.5), it no longer occurs.

@DePasqualeOrg DePasqualeOrg changed the title TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType' Error with latest version of Pandas Jul 4, 2021
@drpalmer
Copy link

drpalmer commented Jul 4, 2021

With the upgrade to Numpy 1.21.0 and Pandas 1.3.0 I've experienced "TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType'"

The offending line of code is line 6 in calendar_helpers: NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]

I've changed my local copy to : NP_NAT = np.array([pd.NaT.asm8.view('i8')], dtype=np.int64)[0]

Recompiled and it seems to work fine.

maread99 added a commit to maread99/exchange_calendars that referenced this issue Jul 4, 2021
@maread99
Copy link
Collaborator

maread99 commented Jul 5, 2021

Another issue following this latest pandas release is that the ExchangeCalendar constructor is now raising a FutureWarning.

The cause is within the creation of the schedule DataFrame, due to conversion of DatetimeIndex values with dtype 'datetime64[ns, UTC]' (self._opens etc.) to 'datetime64[ns]'.

        self.schedule = DataFrame(
            index=_all_days,
            data=OrderedDict(
                [
                    ("market_open", self._opens),
                    ("break_start", self._break_starts),
                    ("break_end", self._break_ends),
                    ("market_close", self._closes),
                ]
            ),
            dtype="datetime64[ns]",
        )

One option would be to change the target dtype to "datetime64[ns, UTC]" thereby defining the schedule columns in terms of UTC. This additional context would be meaningful although I suspect it would open a can of worms with respect to changes it would necessitate within exchange_calendars and its clients. For now I'll add a fix to PR #41 that retains the existing behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants