Skip to content

BUG: pd.factorize with read-only datetime64 numpy array raises ValueError #35650

Closed
@ruchirgarg05

Description

@ruchirgarg05
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

In [1]: pandas.__version__
[PYFLYBY] import pandas
Out[1]: u'0.24.2'

In [2]: arr = numpy.array([numpy.datetime64('2015-11-20T15:06:58.000')])

In [3]: arr.dtype
Out[3]: dtype('<M8[ms]')

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

[PYFLYBY] import pandas as pd
In [5]: pd.factorize(arr)

Problem description

[Construction with non-mutable datetime64 strings]

Expected Output

(array([0]), array(['2015-11-20T15:06:58.000000000'], dtype='datetime64[ns]'))

Output of pd.show_versions()

pandas/_libs/tslibs/conversion.pyx in pandas._libs.tslibs.conversion.ensure_datetime64ns()

/usr/local/python/python-2.7/std/lib/python2.7/site-packages/pandas/_libs/tslibs/conversion.so in View.MemoryView.memoryview_cwrapper()

/usr/local/python/python-2.7/std/lib/python2.7/site-packages/pandas/_libs/tslibs/conversion.so in View.MemoryView.memoryview.cinit()

ValueError: buffer source array is read-only

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions