Description
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 numpy as np
import pandas as pd
def main():
i64 = np.int64
f64 = np.float64
df = pd.DataFrame({
"A": [i64(1), "ASD", f64(2.2)],
"B": [(2,), f64(2.2), i64(1)],
})
a = df.to_dict("list")
print("to_dict('list')")
for key, list_ in a.items():
for value in list_:
print(f"{key}: {value}: {type(value)}")
b = df.to_dict("index")
print("to_dict('index')")
for index, obj in b.items():
for key, value in obj.items():
print(f"{key}: {value}: {type(value)}")
if __name__ == "__main__":
main()
Issue Description
When using to_dict ONLY for orient=list/index the values are not coerced to python native types. We are simply missing a maybe_box_native
call
Expected Behavior
Each value in the resulting to_dict
output should be Python native types, instead we are getting int64's and float64's.
This ONLY happens for orient=list and orient=index, the other orients correctly coerce to native types.
Installed Versions
pandas : 1.4.2
numpy : 1.22.1
pytz : 2021.1
dateutil : 2.8.1
pip : 22.0.3
setuptools : 57.0.0
Cython : 0.29.23
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.1
jinja2 : 3.0.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : 0.6.2
gcsfs : None
markupsafe : 2.0.1
matplotlib : 3.4.2
numba : 0.53.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
snappy : None
sqlalchemy : 1.1.12
tables : None
tabulate : None
xarray : None
xlrd : 1.1.0
xlwt : None
zstandard : None