Skip to content

Series.asof not preserving dtype #16063

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

Closed
fabrice-deschatres opened this issue Apr 20, 2017 · 3 comments · Fixed by #45299
Closed

Series.asof not preserving dtype #16063

fabrice-deschatres opened this issue Apr 20, 2017 · 3 comments · Fixed by #45299
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@fabrice-deschatres
Copy link

fabrice-deschatres commented Apr 20, 2017

Code Sample, a copy-pastable example if possible

from pandas import Series
from datetime import date

if __name__ == "__main__":
    series  = Series([True, False, True], index=[date(2017,1,1), date(2017,2,1), date(2017,3,1)])

    print series.dtype, series.asof([date(2017,4,1)]).dtype

Problem description

With Pandas 0.19.2, I found that dtype was not preserved with asof (bool -> float64), whereas older version of Pandas (ex: version 0.18.0), was preserving bool type

Expected Output

bool, bool

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.12.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 44 Stepping 2, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.19.2
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.23.4
numpy: 1.12.1
scipy: 0.19.0
statsmodels: 0.8.0
xarray: None
IPython: 4.0.1
sphinx: None
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.2
matplotlib: 2.0.0
openpyxl: 2.3.4
xlrd: None
xlwt: None
xlsxwriter: None
lxml: 3.6.1
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
None

@jreback
Copy link
Contributor

jreback commented Apr 20, 2017

so this works if the incoming is already object dtype, IOW you have NaN with a non-native dtype (like bool).

bool with-nan is not a first class type, so not surpising this coerces.

In [13]:     series  = Series([True, False, np.nan, True], index=[date(2017,1,1), date(2017,2,1), date(2017, 2, 2), date(2017,3,1)])

In [14]: series
Out[14]: 
2017-01-01     True
2017-02-01    False
2017-02-02      NaN
2017-03-01     True
dtype: object

In [15]: series.asof([date(2017,4,1)])
Out[15]: 
2017-04-01    True
dtype: object

@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Bug Difficulty Intermediate labels Apr 20, 2017
@jreback jreback added this to the Next Major Release milestone Apr 20, 2017
@fabrice-deschatres
Copy link
Author

Yes, this is the right output:

In [15]: series.asof([date(2017,4,1)])
Out[15]:
2017-04-01 True
dtype: bool

... and that was used to be returned by pandas before version 0.19 (ex: version 0.18.0)

Why would you expect an empty series? The last good value of the original series is True (for 2017/3/1).

@fabrice-deschatres
Copy link
Author

Ok, I don't mind deleting my reply too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants