Fix StringArray.astype for category dtype by siboehm · Pull Request #40450 · pandas-dev/pandas (original) (raw)

This uncovered a bit of a larger issue, basically #37626, but for datetimes & period.

Example:

import pandas as pd t = pd.Series(["1/1/2021", "2/1/2021", None], dtype="period[M]") s = pd.Series(["1/1/2021", "2/1/2021", None], dtype="string").astype("period[M]")

t work, s raises because the None is converted to NA which isn't recognized as datetimelike by period.

Example

import pandas as pd t = pd.Series(["1/1/2021", "2/1/2021"], dtype="object").astype("datetime64[ns]") s = pd.Series(["1/1/2021", "2/1/2021"], dtype="string").astype("datetime64[ns]")

t work, s raises.

However if it's ok I'd open a new issue for it, since it'll be a larger revamp which will take me a few more days.
These "new" issues also aren't regressions like this Categorical issue, they're all already present in 1.2.3.