Closed randolf-scholz closed 1 week ago
[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.
[ ] I have confirmed this bug exists on the main branch of pandas.
import pandas as pd df = pd.DataFrame({"a" : [1, 2], "b" : [3, 4]}, dtype="int64[pyarrow]") assert df["a"].to_numpy().dtype == int # ✅ assert df["b"].to_numpy().dtype == int # ✅ assert df.to_numpy().dtype == int # ❌ object dtype instead of int
All columns convert to int dtypes, but the full frame converts to object dtype.
int
object
One would expect a commutative property: the dtype of DataFrame.to_numpy() should be identical to the dtype of
DataFrame.to_numpy()
np.stack([df[col].to_numpy() for col in df], axis=-1)
(In fact, this provides a naive way of implementing DataFrame.to_numpy().)
Thanks for the report. The core issue is based in https://github.com/pandas-dev/pandas/issues/22791 so will close in favor of that issue
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.
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
All columns convert to
int
dtypes, but the full frame converts toobject
dtype.Expected Behavior
One would expect a commutative property: the dtype of
DataFrame.to_numpy()
should be identical to the dtype of(In fact, this provides a naive way of implementing
DataFrame.to_numpy()
.)Installed Versions