Skip to content

AttributeError: 'numpy.ndarray' object has no attribute '_get_repr' with np.abs on a DatetimeIndex #2948

Closed
@robintw

Description

@robintw

I am trying to find the row of a DataFrame that is closest to a certain datetime. I have my data in a DataFrame which has a DatetimeIndex, and I can't use functions like asof because I need to get the closest row (either before or after the time), so I am trying to implement the standard way of doing this which is getting the absolute difference between each index time and the time I want to find, then finding the row with the minimum difference.

However, there seems to be a strange bug with using np.abs with the pandas index, and it seems to be in the printing of the results stage (relating to __get_repr). Pandas prints things differently depending on how many rows the DataFrame has, and I think this is related here - as running the code on a 200 row DataFrame fails, but on a 100 row DataFrame it works! I've checked that its not some strange value in the DataFrame which is causing the problem, as a 100 row segment from anywhere in my original input file works, whereas a 200 row segment from anywhere fails.

Two input files (aeronet_large.txt with 200 rows and aeronet.txt with 100 rows) and the code I've been using are available at this gist: https://gist.github.com/robintw/631b53fa0cd9dbdabb36, and I asked a StackOverflow question about this (http://stackoverflow.com/questions/15115547/find-closest-row-of-dataframe-to-given-time-in-pandas) where I was recommended to raise an issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions