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
The DataFrame.convert_dtypes method returns the same dataframe (with potentially updated dtypes in certain columns), but because of the internal use of concat, it doesn't necessarily preserve the class type of the dataframe for subclasses.
This stems from the fact that the dataframe is basically decomposed into columns (Series), and then those are combined again into a DataFrame with concat. But at that point, you are concatting Series objects, and concat doesn't know anymore about the original dataframe class. Personally, I would say that the use of concat here is an implementation detail, and that convert_dtypes could easily preserve the original class of the calling dataframe.
Note I am not using pd._testing.SubclassedDataFrame since for this subclass, each column is also a SubclassesSeries, and then concat will actually preserve the subclass.
The text was updated successfully, but these errors were encountered:
The
DataFrame.convert_dtypes
method returns the same dataframe (with potentially updated dtypes in certain columns), but because of the internal use ofconcat
, it doesn't necessarily preserve the class type of the dataframe for subclasses.Noticed this in GeoPandas: geopandas/geopandas#1870
This stems from the fact that the dataframe is basically decomposed into columns (Series), and then those are combined again into a DataFrame with
concat
. But at that point, you are concatting Series objects, and concat doesn't know anymore about the original dataframe class. Personally, I would say that the use ofconcat
here is an implementation detail, and thatconvert_dtypes
could easily preserve the original class of the calling dataframe.Small reproducer without geopandas:
Note I am not using
pd._testing.SubclassedDataFrame
since for this subclass, each column is also a SubclassesSeries, and thenconcat
will actually preserve the subclass.The text was updated successfully, but these errors were encountered: