You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a DataFrame with no rows, the presence of a dtype argument may convert the columns into float64. The problem does not happen if the DataFrame has one or more rows:
This seems to be intended behaviour, as demonstrated by the following test in pandas/tests/frame/test_constructor.py::TestDataFramConstructors::test_constructor_corner
The code responsible for this behaviour is found in pandas/core/dtypes/cast.py, on line 1223. Commenting out these two lines causes the above test, and no others, to fail in the pytest suite.
if is_integer_dtype(dtype) and isna(value):
dtype = np.float64
Good point. Theoretically it could be fixed by making the int cast to float only if an lrange is specified. I can try it out later and submit a PR if the tests pass.
Code Sample
Problem description
When creating a DataFrame with no rows, the presence of a
dtype
argument may convert the columns intofloat64
. The problem does not happen if the DataFrame has one or more rows:Expected Output
Output of
pd.show_versions()
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.18.5-arch1-1-ARCH
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.4
pytest: 3.8.0
pip: 10.0.1
setuptools: 40.2.0
Cython: 0.28.5
numpy: 1.15.1
scipy: 1.1.0
pyarrow: 0.9.0
xarray: 0.10.8
IPython: 6.5.0
sphinx: 1.7.9
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: 0.4.0
matplotlib: 2.2.3
openpyxl: 2.5.5
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.1.0
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.11
pymysql: 0.9.2
psycopg2: None
jinja2: 2.10
s3fs: 0.1.6
fastparquet: 0.1.6
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: