[Solved] “TypeError: data type not understood” comparing dtype np.datetime64

as per this response, I’m comparing a subtype datetime64[ns, US/Central] to np.datetime64:

        columns = self._obj.columns
        for dtype in self._obj.dtypes:
            print("testing:", dtype)
            if np.issubdtype(dtype, np.datetime64):
testing: datetime64[ns, US/Central]
TypeError                                 Traceback (most recent call last)
<ipython-input-6-2ddcb445a42c> in <module>
...(self, dataframe, *dataframes)
    147         for dtype in self._obj.dtypes:
    148             print("testing:", dtype)
--> 149             if np.issubdtype(dtype, np.datetime64):

TypeError: data type not understood

if run head() in this dataframe I get normal timestamps in that column:

0   2020-02-22 12:11:40-06:00   NaN
1   2020-02-22 12:11:41-06:00   NaN

pandas.version ‘1.0.2’
numpy.version ‘1.18.1’
any ideas? thanks

Enquirer: martin


Solution #1:

not ideal, but I fixed this with string comparison:

if (str(dtype).startswith("datetime64")):

Respondent: martin

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.