Skip to content
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

BUG: Creating an empty dataframe #40179

Closed
simon-spier0 opened this issue Mar 2, 2021 · 4 comments
Closed

BUG: Creating an empty dataframe #40179

simon-spier0 opened this issue Mar 2, 2021 · 4 comments
Labels
Bug DataFrame DataFrame data structure Needs Info Clarification about behavior needed to assess issue

Comments

@simon-spier0
Copy link

An empty dataframe can't be created because this error is raised when I try it:
AttributeError: type object 'object' has no attribute 'dtype'

column_names = ["a", "b", "c"]
df = pd.DataFrame([], columns=column_names)

Based on this, it's caused by numpy version. If I install numpy 1.19.5, empty dataframe is created but if I install numpy 1.20.0 (or newer), the error above is raised.

Can this bug be fixed in pandas or in numpy?

Thank you.

@simon-spier0 simon-spier0 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 2, 2021
@phofl
Copy link
Member

phofl commented Mar 2, 2021

This works for me on master with numpy 1.20

Please show your versions and traceback

INSTALLED VERSIONS ------------------ commit : b835ca2 python : 3.8.6.final.0 python-bits : 64 OS : Linux OS-release : 5.8.0-44-generic Version : #50~20.04.1-Ubuntu SMP Wed Feb 10 21:07:30 UTC 2021 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.3.0.dev0+909.gb835ca2fc2
numpy : 1.20.0
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 49.6.0.post20210108
Cython : 0.29.21
pytest : 6.2.1
hypothesis : 6.0.2
sphinx : 3.4.3
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 0.8.5
fastparquet : 0.5.0
gcsfs : 0.7.1
matplotlib : 3.3.3
numexpr : 2.7.2
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 1.0.0
pyxlsb : None
s3fs : 0.4.2
scipy : 1.6.0
sqlalchemy : 1.3.22
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.16.2
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.52.0

Process finished with exit code 0

@phofl phofl added DataFrame DataFrame data structure Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 2, 2021
@simon-spier0
Copy link
Author

Traceback (most recent call last):

  File "C:\Program Files\JetBrains\PyCharm 2020.3.3\plugins\python\helpers\pydev\pydevd.py", line 1477, in _exec

    pydev_imports.execfile(file, globals, locals)  # execute the script

  File "C:\Program Files\JetBrains\PyCharm 2020.3.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile

    exec(compile(contents+"\n", file, 'exec'), glob, loc)

  File "C:/Users/x/Desktop/mtest1/execute.py", line 5, in <module>

    df = pd.DataFrame([], columns=column_names)

  File "C:\Users\x\.virtualenvs\mtest1-YxEr--ER\lib\site-packages\pandas\core\frame.py", line 490, in __init__

    mgr = init_dict({}, index, columns, dtype=dtype)

  File "C:\Users\x\.virtualenvs\mtest1-YxEr--ER\lib\site-packages\pandas\core\internals\construction.py", line 239, in init_dict

    val = construct_1d_arraylike_from_scalar(np.nan, len(index), nan_dtype)

  File "C:\Users\x\.virtualenvs\mtest1-YxEr--ER\lib\site-packages\pandas\core\dtypes\cast.py", line 1449, in construct_1d_arraylike_from_scalar

    dtype = dtype.dtype

AttributeError: type object 'object' has no attribute 'dtype'

python 3.8

numpy: 1.20.1
pandas: 1.0.1
python-dateutil: 2.8.1
pytz: 2021.1
six: 1.15.0

@phofl
Copy link
Member

phofl commented Mar 2, 2021

Please try on newer pandas, 1.2.3 came out yesterday

@simon-spier0
Copy link
Author

simon-spier0 commented Mar 2, 2021

Well, I see I have an older version of Pandas. It's ok now after update to the latest version. Sorry. :)

@phofl phofl added this to the No action milestone Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DataFrame DataFrame data structure Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

2 participants