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
importpandasaspdimportnumpyasnpdf=pd.DataFrame([[1,2],[3,4]], columns=["A", "B"])
dfAB012134df.astype({"A": np.float64, "B": np.float64})
AB01.02.013.04.0df.astype(pd.Series({"A": np.float64, "B": np.float64})) # using a series does not react at all (error or right behaviour)AB012134df.astype(list(pd.Series({"A": np.float64, "B": np.float64}))) # using a type that is not allowed raises error
[...] TypeError: datatypenotunderstood
Problem description
I wanted to parse the columns of a DF with a Series (instead of a dict as stated in the docs). I realised that the types did not change at all nor an error was raised. Casting to dict helped (see in code).
Expected Output
I expect to give the same error as when a wrong data type (e.g. list) is used, or alternatively that it works the same way as a dict. At the moment nothing happens.
I think .astype(series[name, dtype]) should work just like a dictionary.
We try isinstance(dtype, collections.Mapping), which is False for series (it should maybe be true, see #12056. We aren't 100% compatible with the interface though, since .values isn't callable). Alternatively we could replace that isinstance with is_dict_like and it'll work. Interested in submitting a PR?
Code Sample
Problem description
I wanted to parse the columns of a DF with a Series (instead of a dict as stated in the docs). I realised that the types did not change at all nor an error was raised. Casting to dict helped (see in code).
Expected Output
I expect to give the same error as when a wrong data type (e.g. list) is used, or alternatively that it works the same way as a dict. At the moment nothing happens.
The text was updated successfully, but these errors were encountered: