Skip to content

Wrong indexing with time zone support #2897

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
pkaczynski opened this issue Feb 19, 2013 · 7 comments
Closed

Wrong indexing with time zone support #2897

pkaczynski opened this issue Feb 19, 2013 · 7 comments
Labels
Milestone

Comments

@pkaczynski
Copy link

There is something really wrong with ix method while using time support. Simple example:

def test_tz_error(self):
        import pandas, pytz
        from datetime import datetime
        from datetime import timedelta as td
        tz = pytz.timezone('Europe/Warsaw')
        ts_from = tz.localize(datetime(2012, 1, 1, 0, 0))
        ts_to = tz.localize(datetime(2012, 1, 1, 23, 0))
        ttt = pandas.DataFrame(index=pandas.date_range(ts_from, ts_to, freq='H'), 
                               columns=['values'])
        ttt['value'] = range(1,25)
        ts = ts_from
        while ts <= ts_to:
            print ttt.ix[ts]['value']
            ts += td(hours=1)

Should print out number 1,2,3,...,24. However i get:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 24

Why is it from 2, not 1? And why the last value is repeated twice with value 24??

I am using latest release 0.10.1

@Moisan
Copy link
Contributor

Moisan commented Feb 19, 2013

Take a look at this : https://gist.github.com/Moisan/4987028

The problem seems to be coming from the timezone information. It seems that the ix method is doing something wrong since print ttt[ttt.index == ts]['value'][0] will output the values correctly with the timezones.

@stephenwlin
Copy link
Contributor

i believe this is the same issue as #2788 (or #2789, which is related) and fixed in #2785: i tested it using my local copy your example prints 1-24. (I'm slightly confused because I think your case is one that should have already been working before this fix, since you're indexing with tz-aware dates on a tz-aware index, but in any case it seems to be working now...)

@stephenwlin
Copy link
Contributor

Actually, I got it now. The issue is part of #2789: internally the timezone offset was being double counted, so everything was off by one in your case. (The second 24 is a weird corner case thing)

@pkaczynski
Copy link
Author

Thanks for the answers. Is this going to be included in next release?

@stephenwlin
Copy link
Contributor

It's already been merged, so yes, barring anything catastrophic

@wesm
Copy link
Member

wesm commented Mar 12, 2013

Can this be closed? i.e. has been sufficiently unit tested

@stephenwlin
Copy link
Contributor

i think so

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

No branches or pull requests

4 participants