Why was datetime removed from Pandas 1.0?

Viewed 17397

I deal with a lot of data analysis in pandas and use pandas.datetime everyday. Lately I get the warning:

"FutureWarning: The pandas.datetime class is deprecated and will be removed from pandas in a future version. Import from datetime module instead."

I've used Python datetime package before when pandas datetime wouldn't work with I wanted to do, and I understand it is a library that is more related to "date", but does anyone know the idea behind this shift to datetime package?

1 Answers

Summary: datetime (from the Python Standard Libary) was never really a part of Pandas or its API, which the developers are now making a concerted effort to warn about. You can access the datetime class directly:

from datetime import datetime

Detail: Older versions of Pandas (example: 0.20) contained:

from datetime import datetime

in pandas/__init__.py

This meant that, if you really wanted to, you could reference and use pd.datetime, which is really just the standard library's datetime class.

Per Pandas issue #30610 and issue #30296, pandas.datetime is really just standard datetime.datetime. It looks like deprecating them (which, interesting, is done via overriding __getattr__ at the module level*), is done to discourage "roundabout usage" where other 3rd party libraries/modules are brought into the top-level Pandas namespace.

That is, the Pandas library doesn't consider datetime (or numpy) being available in that namespace to be a part of its API, so you shouldn't depend on it being there in the first place.


*Specifically, this looks like:

# pandas/__init__.py
    def __getattr__(name):
        import warnings
        elif name == "datetime":
            warnings.warn(...)
            from datetime import datetime as dt
            return dt
Related