Skip to content

BUG: Series(..) coerces datetime64[non-ns] array differently depending on writable flag #34843

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

Normally, if we create a Series or DataFrame from a numpy array of non-ns datetime64, and the values are within the ns-range, we convert to datetime64[ns] (in sanitize_array).

However, this does not seem to happen if the array is not writeable:

In [9]: arr = np.array(['2020-01-01T00:00:00.000000'], dtype="datetime64[us]") 

In [10]: pd.Series(arr) 
Out[10]: 
0   2020-01-01
dtype: datetime64[ns]

In [11]: arr.flags.writeable = False  

In [12]: pd.Series(arr)  
Out[12]: 
0    2020-01-01 00:00:00
dtype: object

I suppose this is a bug? (@jbrockmendel ?)

It seems this is due to tslibs.conversion.ensure_datetime64ns failing on a read-only buffer, and it started "failing" since pands 0.25

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions