Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] I have confirmed this bug exists on the latest version of pandas.

  • [X] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

data = {"ID": [1, 2, 4], "Names" : ['k', 'X', 'y']}

df = pd.DataFrame(data)
df.head()

Issue Description

It was working fine when I was running it about 7 Hour ago but now it won't work mean while it give me this error TypeError: Cannot convert numpy.ndarray to numpy.ndarray

Expected Behavior

TypeError: Cannot convert numpy.ndarray to numpy.ndarray

Installed Versions

INSTALLED VERSIONS ------------------ commit : d9cdd2ee5a58015ef6f4d15c7226110c9aab8140 python : 3.10.12.final.0 python-bits : 64 OS : Linux OS-release : 6.1.85+ Version : #1 SMP PREEMPT_DYNAMIC Thu Jun 27 21:05:47 UTC 2024 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : en_US.UTF-8 LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.2.2 numpy : 1.26.4 pytz : 2024.2 dateutil : 2.8.2 setuptools : 75.1.0 pip : 24.1.2 Cython : 3.0.11 pytest : 7.4.4 hypothesis : None sphinx : 5.0.2 blosc : None feather : None xlsxwriter : None lxml.etree : 5.3.0 html5lib : 1.1 pymysql : None psycopg2 : 2.9.10 jinja2 : 3.1.4 IPython : 7.34.0 pandas_datareader : 0.10.0 adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.3 bottleneck : 1.4.2 dataframe-api-compat : None fastparquet : None fsspec : 2024.10.0 gcsfs : 2024.10.0 matplotlib : 3.8.0 numba : 0.60.0 numexpr : 2.10.1 odfpy : None openpyxl : 3.1.5 pandas_gbq : 0.24.0 pyarrow : 17.0.0 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.13.1 sqlalchemy : 2.0.36 tables : 3.8.0 tabulate : 0.9.0 xarray : 2024.10.0 xlrd : 2.0.1 zstandard : None tzdata : 2024.2 qtpy : None pyqt5 : None

Comment From: rhshadrach

I would have to guess this is due to an invalid installation. Please try recreating your environment from scratch. If this does not resolve it, post a full stack trace of the error that you get.

Comment From: mohsenhariri

having the same issue.

Comment From: rhshadrach

Can you post a full stack trace?

Comment From: Ibrah-N

Yeah it resolved, actually when you install some dependencies in colab then the session should be restarted in order to make it usable

Comment From: rhshadrach

@mohsenhariri - closing for now. If you are still having issues, post a full stack trace and we can reopen.

Comment From: Geremia

@rhshadrach

Pandas 2.1.4 on Python 3.12.8, with Numpy 1.26.3:

import pandas as pd
data = {"ID": [1, 2, 4], "Names" : ['k', 'X', 'y']}

df = pd.DataFrame(data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.12/site-packages/pandas/core/frame.py", line 778, in __init__
    mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/pandas/core/internals/construction.py", line 480, in dict_to_mgr
    columns = Index(keys) if keys else default_index(0)
              ^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/pandas/core/indexes/base.py", line 565, in __new__
    arr = sanitize_array(data, None, dtype=dtype, copy=copy)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/pandas/core/construction.py", line 654, in sanitize_array
    subarr = maybe_convert_platform(data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/pandas/core/dtypes/cast.py", line 139, in maybe_convert_platform
    arr = lib.maybe_convert_objects(arr)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib.pyx", line 2538, in pandas._libs.lib.maybe_convert_objects
TypeError: Cannot convert numpy.ndarray to numpy.ndarray

Comment From: rhshadrach

@Geremia - can you give details as to how you're running this. Is it locally? A py-file or a notebook? Also can you post the output of pd.show_versions().

Comment From: Geremia

@rhshadrach I'm running it in a python console:

$ python
Python 3.12.8 (main, Dec  4 2024, 14:07:02) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> data = {"ID": [1, 2, 4], "Names" : ['k', 'X', 'y']}
>>> df = pd.DataFrame(data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.12/site-packages/pandas/core/frame.py", line 778, in __init__
    mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/pandas/core/internals/construction.py", line 480, in dict_to_mgr
    columns = Index(keys) if keys else default_index(0)
              ^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/pandas/core/indexes/base.py", line 565, in __new__
    arr = sanitize_array(data, None, dtype=dtype, copy=copy)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/pandas/core/construction.py", line 654, in sanitize_array
    subarr = maybe_convert_platform(data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/pandas/core/dtypes/cast.py", line 139, in maybe_convert_platform
    arr = lib.maybe_convert_objects(arr)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib.pyx", line 2538, in pandas._libs.lib.maybe_convert_objects
TypeError: Cannot convert numpy.ndarray to numpy.ndarray
>>> pd.show_versions()

INSTALLED VERSIONS
------------------
commit                : d9cdd2ee5a58015ef6f4d15c7226110c9aab8140
python                : 3.12.8.final.0
python-bits           : 64
OS                    : Linux
OS-release            : 6.12.6
Version               : #1 SMP PREEMPT_DYNAMIC Thu Dec 19 14:44:30 CST 2024
machine               : x86_64
processor             : AMD Ryzen Threadripper 2990WX 32-Core Processor
byteorder             : little
LC_ALL                : None
LANG                  : en_US.UTF-8
LOCALE                : en_US.UTF-8

pandas                : 2.2.2
numpy                 : 1.26.3
pytz                  : 2024.2
dateutil              : 2.9.0
setuptools            : 75.6.0
pip                   : 24.3.1
Cython                : 3.0.11
pytest                : 8.3.4
hypothesis            : None
sphinx                : 8.1.3
blosc                 : None
feather               : None
xlsxwriter            : None
lxml.etree            : 5.3.0
html5lib              : 1.1
pymysql               : None
psycopg2              : 2.9.9
jinja2                : 3.1.5
IPython               : 8.18.1
pandas_datareader     : None
adbc-driver-postgresql: None
adbc-driver-sqlite    : None
bs4                   : 4.12.3
bottleneck            : None
dataframe-api-compat  : None
fastparquet           : None
fsspec                : None
gcsfs                 : None
matplotlib            : 3.8.4
numba                 : None
numexpr               : None
odfpy                 : None
openpyxl              : None
pandas_gbq            : None
pyarrow               : None
pyreadstat            : None
python-calamine       : None
pyxlsb                : None
s3fs                  : None
scipy                 : 1.12.0
sqlalchemy            : 2.0.36
tables                : None
tabulate              : None
xarray                : None
xlrd                  : None
zstandard             : None
tzdata                : 2024.2
qtpy                  : 2.4.2
pyqt5                 : None
>>> 

Comment From: rhshadrach

Can you reproduce the issue by creating your environment from scratch? If so, can you share what commands you're running to do so.

Comment From: Geremia

@rhshadrach

creating your environment from scratch

That was the issue. I had Pandas 2.2.1 superposed over Pandas 2.2.2 for some reason. I removed the stray 2.2.1 package, and now it works.

Comment From: felix1801

I solved it doing :

sudo pip uninstall pyspark sudo pip uninstall pandas sudo pip uninstall numpy sudo python3 -m pip uninstall numpy

sudo python3 -m pip install pyspark==3.5.4 sudo python3 -m pip install pandas==2.2.3