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.

to_pandas() from binned timed series with bin_time_start

See original GitHub issue

Description

I had a problem with astropy binned time series. I have created such an object using the aggregate_downsample function where I specify the time_bin_start = TimeDelta(-600.,format=‘sec’). When I try to use the to_pandas() function on this binned time series, I get the following error:

  File "C:\Users\bmm93\anaconda3\lib\site-packages\astropy\table\table.py", line 3314, in to_pandas
    kwargs = {'index': out.pop(index)} if index else {}
KeyError: 'time_bin_start'

I have not had trouble with to_pandas() before specifying time_bin_start.

I got response from a user on the ‘Python users in Astronomy’ Facebook group: “This looks like astropy 4.0.x, and a real bug at that. Unfortunately with 4.3 or later I can confirm the same even without specifying time_bin_start! It should work with to_pandas(index=False) – can you check if that returns sensible results? But it would be great if you could submit an issue about this.”

I then tried ‘to_pandas(index=False)’ and I got sensible results. I am using astropy version 4.0.2.

Expected behavior

Actual behavior

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on…]
# Put your Python code snippet here.

System Details

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dhomeiercommented, Aug 5, 2021

Thanks for the bug report! To point out the respective behaviour in 4.0, 4.3 and 5.0, current dev gives

>>> tss = timeseries.aggregate_downsample(ts, time_bin_size=5*u.s)
>>> tss.to_pandas()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/derek/opt/lib/python3.9/site-packages/astropy/table/table.py", line 3744, in to_pandas
    idx = out.pop(index)
KeyError: 'time_bin_start'

even without a time_bin_start option given, whereas the older versions have

>>> tss = timeseries.aggregate_downsample(ts, time_bin_size=5*u.s, time_bin_start=input_time[1])
>>> tss.to_pandas()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/lib/python3.6/site-packages/astropy/table/table.py", line 3310, in to_pandas
    kwargs = {'index': out.pop(index)} if index else {}
KeyError: 'time_bin_start'

– in 4.0.2-4.0.5 only with the time_bin_start option, in 4.3 even without. In all versions both workarounds pass, though with different results/formats:

>>> tss.to_pandas(index=False)
   time_bin_start.jd1  time_bin_start.jd2  time_bin_size           a
0           2457470.0            0.021169            5.0    5.333333
1           2457470.0            0.021227            5.0   30.333333
2           2457470.0            0.021285            5.0  135.666667
>>> table.Table(tss).to_pandas()
                     time_bin_size           a
time_bin_start                                
2016-03-22 12:30:29            5.0    5.333333
2016-03-22 12:30:34            5.0   30.333333
2016-03-22 12:30:39            5.0  135.666667
0reactions
taldcroftcommented, Aug 5, 2021

I think I have a fix, PR coming hopefully.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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