The Wayback Machine - https://web.archive.org/web/20200821064021/https://github.com/pandas-dev/pandas/issues/35650
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ruchirgarg05 opened this issue Aug 10, 2020 · 4 comments · May be fixed by #35775
Open

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

ruchirgarg05 opened this issue Aug 10, 2020 · 4 comments · May be fixed by #35775

Comments

@ruchirgarg05
Copy link

@ruchirgarg05 ruchirgarg05 commented Aug 10, 2020

  • 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

@jreback
Copy link
Contributor

@jreback jreback commented Aug 10, 2020

pls try on 1.1 and/or master

@simonjayhawkins
Copy link
Member

@simonjayhawkins simonjayhawkins commented Aug 11, 2020

works on pandas latest (and master) fails on v1.0.5

>>> pd.__version__
'1.1.0'
>>>
>>> arr = np.array([np.datetime64("2015-11-20T15:06:58.000")])
>>>
>>> arr.dtype
dtype('<M8[ms]')
>>>
>>> arr.flags.writeable = False
>>>
>>> pd.factorize(arr)
(array([0], dtype=int64), array(['2015-11-20T15:06:58.000000000'], dtype='datetime64[ns]'))
>>>
@simonjayhawkins
Copy link
Member

@simonjayhawkins simonjayhawkins commented Aug 12, 2020

works on pandas latest (and master) fails on v1.0.5

This was fixed by #34844.

a8bbe75 is the first new commit
commit a8bbe75
Author: Joris Van den Bossche [email protected]
Date: Thu Jun 18 08:47:44 2020 +0200

BUG: fix construction from read-only non-ns datetime64 numpy array (#34844)
@simonjayhawkins simonjayhawkins changed the title BUG: BUG: pd.factorize with read-only datetime64 numpy array raises ValueError Aug 12, 2020
@avinashpancham
Copy link
Contributor

@avinashpancham avinashpancham commented Aug 16, 2020

take

@avinashpancham avinashpancham linked a pull request that will close this issue Aug 17, 2020
5 of 5 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.