Skip to content

Assignment to mixed-type DataFrame with float32 coerce to float64 #12255

@fnielsen

Description

@fnielsen

Assignment to mixed-type DataFrame with float32 numpy array coerce to float64

>>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame([[1, 2, 'a'], [3, 4, 'b']], dtype=np.float32)
>>> A = df.iloc[:, 0:1].values
>>> df.iloc[:, 0:1] = A
>>> df[0].dtype
dtype('float64')

Shouldn't the result be dtype('float32')?

See also http://stackoverflow.com/questions/35230388/why-does-pandas-coerce-my-numpy-float32-to-float64

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions