Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing a Dask dataframe gives an error cannot import name 'is_datetime64tz_dtype'

I installed Dask in my Jupyter notebook using the below command

!pip install “dask[complete]”

After this when I run the import command


import dask.dataframe as dd

I get the below error.

ImportError                               Traceback (most recent call last)
<ipython-input-13-99db13701da1> in <module>()
  2 import pandas as pd
  3 import dask.array as da
----> 4 import dask.dataframe as dd

D:\Anaconda\lib\site-packages\dask\dataframe\__init__.py in <module>()
  1 from __future__ import print_function, division, absolute_import
  2 
----> 3 from .core import (DataFrame, Series, Index, _Frame, map_partitions,
  4                    repartition, to_delayed)
  5 from .io import (from_array, from_pandas, from_bcolz,

D:\Anaconda\lib\site-packages\dask\dataframe\core.py in <module>()
 29 from ..base import Base, compute, tokenize, normalize_token
 30 from ..async import get_sync
---> 31 from . import methods
 32 from .utils import (meta_nonempty, make_meta, insert_meta_param_description,
 33                     raise_on_meta_error)

D:\Anaconda\lib\site-packages\dask\dataframe\methods.py in <module>()
  5 from toolz import partition
  6 
----> 7 from .utils import PANDAS_VERSION
  8 
  9 

D:\Anaconda\lib\site-packages\dask\dataframe\utils.py in <module>()
 13 import pandas as pd
 14 import pandas.util.testing as tm
---> 15 from pandas.core.common import is_datetime64tz_dtype
 16 import toolz
 17 

ImportError: cannot import name 'is_datetime64tz_dtype'

Note- My Pandas version is

pandas 0.23.4

Can anyone help me know here? Thanks.

like image 944
Mallikarjun S B Avatar asked Oct 19 '25 14:10

Mallikarjun S B


2 Answers

The relevant code in dask.dataframe.utils looks like

try:
    from pandas.api.types import is_datetime64tz_dtype
except ImportError:
    # pandas < 0.19.2
    from pandas.core.common import is_datetime64tz_dtype

It has been this way for over a year, suggesting that you are importing a dask that is rather old. Note that the difference between the lines in the code now and the ones reported in your traceback.

Perhaps your pip install command should have been set to upgrade (i.e., you installed dask some long time ago and forgot about it), or perhaps there is some other dependency in your system that prevents you from installing the latest dask, or simply that you are installing a new version of dask, but the old version is still the one being imported. The output of the pip command should help you identify which, and be sure to check the paths it reports versus the paths in the error above.

Also, you may find that managing environments and dependencies with conda is easier - if you are in a position to make the switch, that is.

like image 117
mdurant Avatar answered Oct 22 '25 05:10

mdurant


Try to restart your kernel after the installation. it should work.

like image 45
YosDos Avatar answered Oct 22 '25 04:10

YosDos