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’
`

About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 29 (14 by maintainers)
Commits related to this issue
- Increased required pandas version Changes in numpy caused the issue seen at these links: (https://stackoverflow.com/a/65999399), (https://github.com/pandas-dev/pandas/issues/39520). I stopped at 1.1.... — committed to ojustino/backstroke by ojustino 3 years ago
- Increased required pandas version Changes in numpy caused the issue seen at these links: (https://stackoverflow.com/a/65999399), (https://github.com/pandas-dev/pandas/issues/39520). I stopped at 1.1.... — committed to ojustino/backstroke by ojustino 3 years ago
- Increased required pandas version Changes in numpy caused the issue seen at these links: (https://stackoverflow.com/a/65999399), (https://github.com/pandas-dev/pandas/issues/39520). I stopped at 1.1.... — committed to ojustino/backstroke by ojustino 3 years ago
- Downgrade numpy to fix https://github.com/pandas-dev/pandas/issues/39520 — committed to javabudd/jtrader by javabudd 3 years ago
FWIW; if you are stuck on
pandas==0.24.2(don’t ask); downgrading tonumpy==1.19.5worksyes, I try to pip install -U
pandas==1.0.5(or updatenumpy==0.19.5), the problem is fixed. whenpnadas==1.0.3andnumpy==1.20the problem will reproduceI got same errors on my environment. As @jreback pointed out, the combination of older version of pandas (at least
pandas>=0.25.2) and thenumpy==1.2.0produce theAttributeError. It seems the problem is fixed inpandas==1.0.5.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.