Skip to content

API/DOC: unclear scope of index.asof #8815

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
jorisvandenbossche opened this issue Nov 14, 2014 · 3 comments
Closed

API/DOC: unclear scope of index.asof #8815

jorisvandenbossche opened this issue Nov 14, 2014 · 3 comments

Comments

@jorisvandenbossche
Copy link
Member

From http://stackoverflow.com/questions/26918045/python-pandas-typeerror-cannot-compare-type-timestamp-with-type-float

The docstring of Index.asof says:

In [73]: pd.Index.asof?
Type:        instancemethod
String form: <unbound method Index.asof>
File:        c:\anaconda\lib\site-packages\pandas\core\index.py
Definition:  pd.Index.asof(self, label)
Docstring:
For a sorted index, return the most recent label up to and including
the passed label. Return NaN if not found

while asof only works for a time series.

  • Clarify the docs that asof only works for DatetimeIndex (and PeriodIndex?)

  • Why is this actually restricted to timestamps? This functions seems also possibly useful to me for other index types? Something like

    In [74]: idx = pd.Index([1,2,3,8,9])
    
    In [75]: idx.asof(5)    # gives now TypeError
    3
    

    Instead of having to do:

    In [78]: idx[idx.searchsorted(5) - 1]
    Out[78]: 3
    
@jorisvandenbossche jorisvandenbossche changed the title API/ODC: unclear scope of index.asof API/DOC: unclear scope of index.asof Nov 14, 2014
@jorisvandenbossche jorisvandenbossche added this to the 0.16.0 milestone Nov 14, 2014
@jreback
Copy link
Contributor

jreback commented Nov 14, 2014

actually a much bigger issue is that this should raise on a non-monotonic index (or at least show a PerformanceWarning). and prob should provide a side argument as well (and thus its very close to searchsorted, except when the label is actually in the index).

@jreback
Copy link
Contributor

jreback commented Mar 6, 2015

@shoyer now that you fixed .asof close?

@shoyer
Copy link
Member

shoyer commented Mar 6, 2015

Indeed, it's fixed!

@shoyer shoyer closed this as completed Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants