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: Series.count() raises exception after upgrading from v0.24.1 to v0.25.3 if use_inf_as_na is enabled for a DateTime series. #29478

Closed
thy09 opened this issue Nov 8, 2019 · 3 comments · Fixed by #29888
Labels
Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@thy09
Copy link
Contributor

thy09 commented Nov 8, 2019

Code Sample, a copy-pastable example if possible

# Your code here
import pandas as pd
from datetime import datetime

if __name__ == '__main__':
    s = pd.Series([datetime.now()])
    with pd.option_context('use_inf_as_na', True):
        s.count()

Problem description

Previously with pandas v0.24.1, the above code works well,
however, after I upgrade the version to v0.25.3,
the above code raises an exception:
AttributeError: 'DatetimeArray' object has no attribute '_constructor'

It seems that something goes wrong when passing a DatetimeArray to _isna_old.
I think it is a bug introduced in some recent update.

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit : None
python : 3.6.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 0.25.3
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.0
pip : 18.1
setuptools : 40.6.2
Cython : None
pytest : 4.3.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.9.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.12.1
pytables : None
s3fs : None
scipy : 1.2.1
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@thy09 thy09 changed the title Series.count() raises exception in v0.25.3 if use_inf_as_na is enabled for a DateTime series. BUG: Series.count() raises exception in v0.25.3 if use_inf_as_na is enabled for a DateTime series. Nov 8, 2019
@thy09 thy09 changed the title BUG: Series.count() raises exception in v0.25.3 if use_inf_as_na is enabled for a DateTime series. BUG: Series.count() raises exception after upgrading from v0.24.1 to v0.25.3 if use_inf_as_na is enabled for a DateTime series. Nov 8, 2019
@jorisvandenbossche jorisvandenbossche added the Regression Functionality that used to work in a prior pandas version label Nov 24, 2019
@jorisvandenbossche jorisvandenbossche added this to the 1.0 milestone Nov 24, 2019
@jorisvandenbossche
Copy link
Member

@thy09 late reply, but thanks for the report! I can confirm this is a regression compared to 0.24

I think the fix should be to add ExtensionArray to this isinstance check here:

elif isinstance(obj, (ABCSeries, np.ndarray, ABCIndexClass)):

You're certainly welcome to look into it and do a PR!

@thy09
Copy link
Contributor Author

thy09 commented Nov 26, 2019

In _isna_new, I see 3 more types ABCExtensionArray, ABCDatetimeArray, ABCTimedeltaArray,,
should we follow the same logic and add these three types to isna_old?

@jorisvandenbossche
Copy link
Member

Normally, if something is a DatetimeArray or TimedeltaArray, it is also an ExtensionArray (it are subclasses), so I would think that only adding ABCExtensionArray would be enough. But you might need to test that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants