New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type #18355
Comments
There is a unfortuate incompatibility with old pandas and 1.20. Updating pandas to a newer version should fix it, see also pandas-dev/pandas#39520 (comment) Updating to |
@seberg Any idea why someone might be suddenly seeing this error when calling |
@jessdwitch I am not sure if there are other (likely) ways to get this error, and I doubt it is possible with the above example (or a similar one, such as creating an empty dataframe IIRC). Can you double check |
Thank you for the quick reply! I did check those already, since there are multiple versions installed ( |
Hmm, can you post an example and the full traceback? I am wondering if I mixed up the issues and this one was not related to 1.20.x at all. To be honest, if you are not running 1.20.x, then searching/asking on pandas is more likely to be successfull. |
Gotcha. Tbh asking around pandas was my first thought, but this is literally the only google result with this error (well, this and an SO thread Mahendra created). Here's the traceback starting with the
|
Sorry, do you have a minimal reproducer, preferably printing out the versions? It does look like this issue, but in that case the pandas code in Long story short, it looks a lot like this issue but I if you are really not on NumPy 1.20 |
Hey sorry for disappearing, but you were totally right. For some reason the Conda environment was using the pandas from within the env, but the numpy from outside, causing the conflict. We ended up just downgrading the numpy from outside the env to match the one within the env and everything is happy now. Thank you so much! |
Closing. Please reopen if needed. |
Hi I tried updating pandas to 1.0.5 and I still get the same error message. TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type . I have a numpy version of 1.20.1. |
@aarthim123 this issue is specifically about the error in the title. Please open an error on an appropriate issue tracker for problems with installing pandas on conda please use a more appropriate forum. You might have better luck searching for similar error messages. If you do open an issue, you probably should report the output of |
@aarthim123 use ..pip install numpy==1.16.5 |
I just saw this:- <class 'numpy.ndarray'> <class 'numpy.ndarray'>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-14380fd16e5f> in <module>
49 print(type(v_list[i]), type(face_list[i]) )
50 #dataset = pd.DataFrame({'Group':'Neoprot-Ordovician','Surface': s, 'X': v_list[i][:, 0], 'Y': v_list[i][:, 1], 'Z': v_list[i][:, 2], 'SG': -1 })
---> 51 dataset = pd.DataFrame({'Group':'Neoprot-Ordovician','Surface': s, 'X': v_list[i][:, 0].astype(float) })
52 dataset["Name"] = metadata_list[i]["NAME"]
53 dataset["CRS"] = str(metadata_list[i]["CRS"])
~\AppData\Local\Continuum\anaconda3\envs\gemgis\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
433 )
434 elif isinstance(data, dict):
--> 435 mgr = init_dict(data, index, columns, dtype=dtype)
436 elif isinstance(data, ma.MaskedArray):
437 import numpy.ma.mrecords as mrecords
~\AppData\Local\Continuum\anaconda3\envs\gemgis\lib\site-packages\pandas\core\internals\construction.py in init_dict(data, index, columns, dtype)
252 arr if not is_datetime64tz_dtype(arr) else arr.copy() for arr in arrays
253 ]
--> 254 return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
255
256
~\AppData\Local\Continuum\anaconda3\envs\gemgis\lib\site-packages\pandas\core\internals\construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype)
67
68 # don't force copy because getting jammed in an ndarray anyway
---> 69 arrays = _homogenize(arrays, index, dtype)
70
71 # from BlockManager perspective
~\AppData\Local\Continuum\anaconda3\envs\gemgis\lib\site-packages\pandas\core\internals\construction.py in _homogenize(data, index, dtype)
320 val = dict(val)
321 val = lib.fast_multiget(val, oindex.values, default=np.nan)
--> 322 val = sanitize_array(
323 val, index, dtype=dtype, copy=False, raise_cast_failure=False
324 )
~\AppData\Local\Continuum\anaconda3\envs\gemgis\lib\site-packages\pandas\core\construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
463 value = maybe_cast_to_datetime(value, dtype)
464
--> 465 subarr = construct_1d_arraylike_from_scalar(value, len(index), dtype)
466
467 else:
~\AppData\Local\Continuum\anaconda3\envs\gemgis\lib\site-packages\pandas\core\dtypes\cast.py in construct_1d_arraylike_from_scalar(value, length, dtype)
1459 value = ensure_str(value)
1460
-> 1461 subarr = np.empty(length, dtype=dtype)
1462 subarr.fill(value)
1463
TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type |
pandas 1.0.1 py38he350917_0 conda-forge |
Please just update your pandas. If you want to stay on If you don't want to upgrade pandas for whatever reason, you may have to stick to NumPy 1.19.x as well. |
For reference if someone else comes across it - it happened due to installing something else downgrading the pandas version. |
Addresses this problem: numpy/numpy#18355
pip install pandas --upgrade |
pip install --upgrade numpy |
Hi, I've already upgrade both pandas (0.24.2) and numpy (1.21.5). When I tried data.info(), it still doesn't work. Any thoughts? `--------------------------------------------------------------------------- /opt/apps/apps/binapps/anaconda3/2019.07/lib/python3.7/site-packages/pandas/core/frame.py in info(self, verbose, buf, max_cols, memory_usage, null_counts) /opt/apps/apps/binapps/anaconda3/2019.07/lib/python3.7/site-packages/pandas/core/frame.py in memory_usage(self, index, deep) /opt/apps/apps/binapps/anaconda3/2019.07/lib/python3.7/site-packages/pandas/core/series.py in init(self, data, index, dtype, name, copy, fastpath) /opt/apps/apps/binapps/anaconda3/2019.07/lib/python3.7/site-packages/pandas/core/internals/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure) /opt/apps/apps/binapps/anaconda3/2019.07/lib/python3.7/site-packages/pandas/core/dtypes/cast.py in construct_1d_arraylike_from_scalar(value, length, dtype) TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type |
Similarly - this is still an issue for me pandas-1.0.1 The low pandas version is being enforced by the numpy version. It does work if I enforce pip install pandas>=1.3 though |
The last time I saw someone who updated their pandas version and then still had the problem, had an environment issue that made them pick up the wrong pandas version after all. Please double check |
I am having the same issue. I checked the versions:
same error: What should I do? Update: |
Yes. I have checked both script and terminal again. pandas == 0.24.2 The error doesn't disappear |
@dinhtrang24 that pandas version is known to be too old. I had asked Luis, because I though 0.24.3 may be new enough (I am not quite sure). You have to either upgrade pandas, since it is an old version, or if you are stuck with such an old pandas version downgrade NumPy. |
@seberg Hi, thanks for the reply. I figured out the problem is that I have installed different versions of pandas and numpy using pip and pip3. After upgrading and matching their versions, the problem was solved. |
Solving Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type from numpy/numpy#18355
Solving Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type from numpy/numpy#18355
Hi I am not sure what to do and how to get rid of this on Azure ML studio. |
the problem I have seen in Azure Notebooks is the way that we install dependencies due to not proper documentation. The best thing is:
Then in notebooks select the kernel. %pip install --> installs on current running kernel More info here. Do it from scratch and please reply if it helped |
Thanks for prompt response @levalencia |
Check the official conda documentation, maybe a syntax error: |
Reproducing code example:
Error message:
NumPy/Python version information:
The text was updated successfully, but these errors were encountered: