Skip to content

BUG: Data type is float64 when Dataframe is initialized with array of shape (0, 0)  #55649

Open
@GianlucaFicarelli

Description

@GianlucaFicarelli

Pandas version checks

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

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

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

Reproducible Example

import pandas as pd
import numpy as np

a = np.array([], dtype=np.int32).reshape((0, 0))
print(repr(pd.DataFrame(a).values))

Output:
array([], shape=(0, 0), dtype=float64)

Issue Description

I found this edge case when initializing a DataFrame with an array of shape (0, 0).
In the previous example, values always contains an array with dtype float64, regardless of the initial dtype of the array.
(Long story short, I found the issue because of a FutureWarning when concatenating)

Expected Behavior

Is the initialization of the DataFrame in the previous example considered valid?
Should the original dtype be preserved?

Installed Versions

INSTALLED VERSIONS

commit : e86ed37
python : 3.11.1.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Fri Sep 15 16:17:23 PDT 2023; root:xnu-8020.240.18.703.5~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : None
LOCALE : en_US.UTF-8

pandas : 2.1.1
numpy : 1.26.1
pytz : 2023.3
dateutil : 2.8.2
setuptools : 68.1.2
pip : 23.2.1
Cython : 3.0.0
pytest : 7.3.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.14.0
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : 2023.7.0
fsspec : 2023.6.0
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 12.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.1
sqlalchemy : None
tables : 3.8.0
tabulate : None
xarray : 2023.7.0
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsDataFrameDataFrame data structureDtype ConversionsUnexpected or buggy dtype conversions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions