-
-
Couldn't load subscription status.
- Fork 19.2k
Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
I'm working on updating pint-pandas to 0.25.1 before the latest version... -
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
TypeError Traceback (most recent call last) c:\users\a\repos\pint\pint\quantity.py in __getitem__(self, key) 1737 try: -> 1738 return type(self)(self._magnitude[key], self._units) 1739 except PintTypeError: TypeError: 'float' object is not subscriptable During handling of the above exception, another exception occurred: TypeError Traceback (most recent call last) <ipython-input-14-67c12fe72115> in <module> ----> 1 self.test_where_series(data, na_value, as_frame) c:\users\a\repos\pint-pandas\pintpandas\test_pandas_interface.py in test_where_series(self, data, na_value, as_frame) 266 cond = cond.reshape(-1, 1) 267 --> 268 result = ser.where(cond) 269 expected = pd.Series( 270 cls._from_sequence([a, a, na_value, na_value], dtype=data.dtype) ~\anaconda3\envs\py37_pd251\lib\site-packages\pandas\core\generic.py in where(self, cond, other, inplace, axis, level, errors, try_cast) 9274 other = com.apply_if_callable(other, self) 9275 return self._where( -> 9276 cond, other, inplace, axis, level, errors=errors, try_cast=try_cast 9277 ) 9278 ~\anaconda3\envs\py37_pd251\lib\site-packages\pandas\core\generic.py in _where(self, cond, other, inplace, axis, level, errors, try_cast) 9121 errors=errors, 9122 try_cast=try_cast, -> 9123 axis=block_axis, 9124 ) 9125 ~\anaconda3\envs\py37_pd251\lib\site-packages\pandas\core\internals\managers.py in where(self, **kwargs) 555 556 def where(self, **kwargs): --> 557 return self.apply("where", **kwargs) 558 559 def setitem(self, **kwargs): ~\anaconda3\envs\py37_pd251\lib\site-packages\pandas\core\internals\managers.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs) 436 kwargs[k] = obj.reindex(b_items, axis=axis, copy=align_copy) 437 --> 438 applied = getattr(b, f)(**kwargs) 439 result_blocks = _extend_blocks(applied, result_blocks) 440 ~\anaconda3\envs\py37_pd251\lib\site-packages\pandas\core\internals\blocks.py in where(self, other, cond, align, errors, try_cast, axis) 2005 set_other = other 2006 else: -> 2007 set_other = other[icond] 2008 try: 2009 result[icond] = set_other c:\users\a\repos\pint\pint\quantity.py in __getitem__(self, key) 1742 raise TypeError( 1743 "Neither Quantity object nor its magnitude ({})" -> 1744 "supports indexing".format(self._magnitude) 1745 ) 1746 TypeError: Neither Quantity object nor its magnitude (nan)supports indexingProblem description
I'm having trouble with this test as pandas is trying to index into a scalar. I believe this is because this line returns false:
pandas/pandas/core/internals/blocks.py
Line 1831 in 185a654
| if lib.is_scalar(other): |
import pintpandas import matplotlib.pyplot as plt import numpy as np import pint import pandas as pd ureg=pint.UnitRegistry() PA_= pintpandas.PintArray PT_ = pintpandas.PintType PT_.ureg = ureg Q_=ureg.Quantity from pandas._libs import NaT, lib, tslib, tslibs lib.is_scalar(Q_(1,'m')) FalseExpected Output
lib.is_scalar(Q_(1,'m')) TrueOutput of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 0.25.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3.post20200330
Cython : 0.29.15
pytest : 5.4.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None