python - Why does Pandas coerce my numpy float32 to float64? -


why pandas coerce numpy float32 float64 in piece of code:

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

the behavior seems odd me wonder if bug. on pandas version 0.17.1 (updated pypi version) , note there has been coercing bugs addressed, see https://github.com/pydata/pandas/issues/11847 . haven't tried piece of code updated github master.

is bug or misunderstand "feature" in pandas? if feature, how around it?

(the coercing problem relates question asked performance of pandas assignments: assignment of pandas dataframe float32 , float64 slow)

i think worth posting github issue. behavior inconsistent.

the code takes different branch based on whether dataframe mixed-type or not (source).

  • in mixed-type case ndarray converted python list of float64 numbers , converted float64 ndarray disregarding dataframe's dtypes information (function maybe_convert_objects()).

  • in non-mixed-type case dataframe content updated pretty directly (source) , dataframe keeps float32 dtypes.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -