pandas: BUG: AttributeError: type object 'object' has no attribute 'dtype' with numpy 1.20.x and pandas versions 1.0.4 and earlier

root@548977c7dc-62l72:/app# pip list | grep pandas pandas 1.0.3

In ipython ,i try initializing df

` In [1]: import pandas as pd

In [2]: pd.DataFrame([],columns=[‘a’,‘b’,‘c’])

AttributeErrorTraceback (most recent call last) <ipython-input-2-ea4921e768b2> in <module> ----> 1 pd.DataFrame([],columns=[‘clicks’, ‘uclicks’, ‘impressions’])

/usr/local/lib/python3.8/site-packages/pandas/core/frame.py in init(self, data, index, columns, dtype, copy) 488 mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy) 489 else: –> 490 mgr = init_dict({}, index, columns, dtype=dtype) 491 else: 492 try:

/usr/local/lib/python3.8/site-packages/pandas/core/internals/construction.py in init_dict(data, index, columns, dtype) 237 else: 238 nan_dtype = dtype –> 239 val = construct_1d_arraylike_from_scalar(np.nan, len(index), nan_dtype) 240 arrays.loc[missing] = [val] * missing.sum() 241

/usr/local/lib/python3.8/site-packages/pandas/core/dtypes/cast.py in construct_1d_arraylike_from_scalar(value, length, dtype) 1438 else: 1439 if not isinstance(dtype, (np.dtype, type(np.dtype))): -> 1440 dtype = dtype.dtype 1441 1442 if length and is_integer_dtype(dtype) and isna(value):

AttributeError: type object ‘object’ has no attribute ‘dtype’ ` image

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 29 (14 by maintainers)

Commits related to this issue

Most upvoted comments

FWIW; if you are stuck on pandas==0.24.2 (don’t ask); downgrading to numpy==1.19.5 works

FWIW; if you are stuck on pandas==0.24.2 (don’t ask); downgrading to numpy==1.19.5 works THANK YOU also works with pandas==0.25.3

I got same errors on my environment. As @jreback pointed out, the combination of older version of pandas (at least pandas>=0.25.2) and the numpy==1.2.0 produce the AttributeError. It seems the problem is fixed in pandas==1.0.5.

$ pip install -u pandas==1.0.1
$ pip install -u pandas==1.2.0
>>> import pandas as pd
>>> pd.DataFrame(columns=['a'])

yes, I try to pip install -U pandas==1.0.5 (or update numpy==0.19.5 ), the problem is fixed. when pnadas==1.0.3 and numpy==1.20 the problem will reproduce

I got same errors on my environment. As @jreback pointed out, the combination of older version of pandas (at least pandas>=0.25.2) and the numpy==1.2.0 produce the AttributeError. It seems the problem is fixed in pandas==1.0.5.

$ pip install -u pandas==1.0.1
$ pip install -u pandas==1.2.0
>>> import pandas as pd
>>> pd.DataFrame(columns=['a'])

the numpy break is intentional (though unsure why this didn’t come up on our prior testing)

as dtypes definitions are being updated

Found the same issue this morning due to some CI tests failing. Python==3.8.2 and pandas==1.0.1.

CI tests ran again successfully after bumping to pandas==1.2.1.