question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Iteration over DatetimeIndex stops at 10000

See original GitHub issue

Code Sample

import pandas as pd

num_index = pd.Index(range(20000))
hour_index = pd.date_range('2000-01-01', periods=20000, freq='H')
minute_index = pd.date_range('2000-01-01', periods=20000, freq='min')

a = 0
for i in num_index: # OK
    a += 1

b = 0
for i in hour_index: # unexpectedly
    b += 1

c = 0
for i in minute_index: # unexpectedly
    c += 1

a, b, c # -> (20000, 10000, 10000)

Problem description

Iteration over DatetimeIndex stops unexpectedly when it’s evaluated 10000 times.

NOTE : this happened in 0.23.0rc2, not 0.22.0

Expected Output

(20000, 20000, 20000)

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 3.10.0-693.21.1.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: ja_JP.UTF-8 LOCALE: ja_JP.UTF-8

pandas: 0.23.0rc2 pytest: None pip: 10.0.1 setuptools: 39.1.0 Cython: None numpy: 1.14.3 scipy: None pyarrow: None xarray: None IPython: None sphinx: None patsy: None dateutil: 2.7.2 pytz: 2018.4 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: None openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None sqlalchemy: None pymysql: None psycopg2: None jinja2: None s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
cbertinatocommented, May 13, 2018

The issue is not so much about dimensionality as it is about the identity of the index as an iterator. This leads to a somewhat deeper question: does it matter whether the index itself is an iterator? Perhaps the answer is: if the tests pass, it doesn’t matter.

If it does matter, then another solution is to make a separate iterator for indexes, instead of returning the index itself from __iter__.

Anyhow, something along the lines of what you suggest would fix it, though something a bit more general, such as not isinstance(tuples, Index) might be better in case something like this crops up for other indexes.

0reactions
kittokucommented, May 13, 2018

A separate iterator sounds good. All of the three test passed because DatetimeIndex itself is not a iterator. I’m going to post a PR later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pandas: iterate over Series with datetime index by index and ...
Is there anyway to do this without iterating? If not, how can I iterate and read the date value? EDIT, in response to...
Read more >
Time series / date functionality — pandas 1.5.2 documentation
Fast shifting using the shift method on pandas objects. Unioning of overlapping DatetimeIndex objects with the same frequency is very fast (important for...
Read more >
Python – Convert pandas DateTimeIndex to Unix Time – iTecNote
The loop iterates on a list, but the list expands while the loop is being iterated. It's a concise way to go through...
Read more >
How to iterate over DataFrame rows (and should you?)
They may not understand the “correct” way to work with DataFrames yet, but even experienced pandas and NumPy developers will consider iterating over...
Read more >
backtesting.backtesting API documentation
The passed data frame can contain additional columns that can be used by the strategy (e.g. sentiment info). DataFrame index can be either...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found