Skip to content

Doctests don't pass with pandas 3 #11129

@jsignell

Description

@jsignell

What is your issue?

It isn't showing up in CI because we aren't running doctests in an env with pandas 3, but if you update to pandas 3 and run doctests a lot of them fail. This is despite the fact that none of the regular tests fail.

The biggest source of difference is that the default unit has changed for pd.date_range when the input is a string. It is now us rather than ns. This dtype shows up in the repr so it is very common to see datetime64[ns] in docstrings.

There are a couple solutions that works across both pandas 2 and pandas 3:

  • set the units in every pd.date_range call.
  • use xr.date_range (which I just learned existed) more often

The downside of those options is that they are slightly less legible. The third option is to just switch the expected output to datetime[us], but that has the downside of only passing if pandas >=3.

Note that there are several other places where the dtype is str rather than object with pandas>=3 so we might end up only getting doctests that pass with a particular major version of pandas anyways.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CIContinuous Integration tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions