Description
I have checked that this issue has not already been reported.
[X ] 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.
This seems related to: #37174
however it shows up under different conditions - appears to be triggered by comparison involving NaN.
Code Sample, a copy-pastable example
print(temp)
temp[temp>180]=temp[temp>180]-360
Output:
2016-12-27 02:02:09.000 182.220
2016-12-27 02:02:09.017 182.226
2016-12-27 02:02:09.033 182.227
2016-12-27 02:02:09.050 182.222
2016-12-27 02:02:09.066 NaN
dtype: float64
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/series.py in __setitem__(self, key, value)
999 try:
-> 1000 self._set_with_engine(key, value)
1001 except (KeyError, ValueError):
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/series.py in _set_with_engine(self, key, value)
1032 # fails with AttributeError for IntervalIndex
-> 1033 loc = self.index._engine.get_loc(key)
1034 validate_numeric_casting(self.dtype, value)
pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()
TypeError: '2016-12-27 02:02:09.000 True
2016-12-27 02:02:09.017 True
2016-12-27 02:02:09.033 True
2016-12-27 02:02:09.050 True
2016-12-27 02:02:09.066 False
dtype: bool' is an invalid key
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-33-85e39ae5f3f1> in <module>
3 temp=temp.head(5)
4 print(temp.head())
----> 5 temp[temp>180]=temp[temp>180]-360
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/series.py in __setitem__(self, key, value)
1018 key = np.asarray(key, dtype=bool)
1019 try:
-> 1020 self._where(~key, value, inplace=True)
1021 except InvalidIndexError:
1022 self.iloc[key] = value
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/generic.py in _where(self, cond, other, inplace, axis, level, errors, try_cast)
8778 if other.ndim <= self.ndim:
8779
-> 8780 _, other = self.align(
8781 other, join="left", axis=axis, level=level, fill_value=np.nan
8782 )
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/series.py in align(self, other, join, axis, level, copy, fill_value, method, limit, fill_axis, broadcast_axis)
4272 broadcast_axis=None,
4273 ):
-> 4274 return super().align(
4275 other,
4276 join=join,
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/generic.py in align(self, other, join, axis, level, copy, fill_value, method, limit, fill_axis, broadcast_axis)
8557 )
8558 elif isinstance(other, ABCSeries):
-> 8559 return self._align_series(
8560 other,
8561 join=join,
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/generic.py in _align_series(self, other, join, axis, level, copy, fill_value, method, limit, fill_axis)
8660 join_index, lidx, ridx = None, None, None
8661 else:
-> 8662 join_index, lidx, ridx = self.index.join(
8663 other.index, how=join, level=level, return_indexers=True
8664 )
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/indexes/datetimelike.py in join(self, other, how, level, return_indexers, sort)
884
885 this, other = self._maybe_utc_convert(other)
--> 886 return Index.join(
887 this,
888 other,
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/indexes/base.py in join(self, other, how, level, return_indexers, sort)
3500 elif self.is_monotonic and other.is_monotonic:
3501 try:
-> 3502 return self._join_monotonic(
3503 other, how=how, return_indexers=return_indexers
3504 )
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/indexes/base.py in _join_monotonic(self, other, how, return_indexers)
3800 join_index = self
3801 lidx = None
-> 3802 ridx = self._left_indexer_unique(sv, ov)
3803 elif how == "right":
3804 join_index = other
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/indexes/datetimelike.py in wrapper(left, right)
62 right = right.view("i8")
63
---> 64 results = joinf(left, right)
65 if with_indexers:
66 # dtype should be timedelta64[ns] for TimedeltaIndex
pandas/_libs/join.pyx in pandas._libs.join.left_join_indexer_unique()
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/_libs/join.cpython-38-x86_64-linux-gnu.so in View.MemoryView.memoryview_cwrapper()
~/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/_libs/join.cpython-38-x86_64-linux-gnu.so in View.MemoryView.memoryview.__cinit__()
ValueError: buffer source array is read-only
Problem description
See error above
Expected Output
I would have expected:
- the 'NA' value to be ignored in comparison without causing an error
- If an error is due to NA, I expect to see appropriate message, instead of 'read-only' being thrown
Output of pd.show_versions()
INSTALLED VERSIONS
commit : db08276
python : 3.8.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-118-generic
Version : #119-Ubuntu SMP Tue Sep 8 12:30:01 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20201009
Cython : 0.29.21
lxml.etree : 4.5.2
jinja2 : 2.11.2
IPython : 7.18.1
fsspec : 0.8.4
fastparquet : 0.4.1
matplotlib : 3.3.2
pyarrow : 0.17.1
scipy : 1.5.2
xarray : 0.16.1
numba : 0.51.2
Activity
dmitra79 commentedon Oct 19, 2020
@dsaxton Does #37181 cover this?
dsaxton commentedon Oct 19, 2020
It seems like a different issue to me. Can you create a copy / pasteable reproducible example so others can investigate?
dmitra79 commentedon Oct 20, 2020
@dsaxton Here is an example:
[-]BUG: NaN in comparison causes ValueError: buffer source array is read-only[/-][+]BUG: another ValueError: buffer source array is read-only[/+]zeromh commentedon Oct 20, 2020
I was have the same error when using the
rank
method. Should I file as a new Issue, or is this all related?Output:
dsaxton commentedon Oct 20, 2020
I think it's related but the fix won't be identical, so probably warrants a separate issue. From some comments it looks like this might require at least Cython 3.
dmitra79 commentedon Oct 29, 2020
Any movement on this? It's still marked as 'Needs Triage'?
jreback commentedon Oct 29, 2020
rank is already patched for master and 1.1.4
@dmitra79 can u try on master
dmitra79 commentedon Nov 2, 2020
@jreback
I just tried this on master (created clean environment, downloaded and buolt master) and got the same error: