Skip to content

TST: Test failures with pandas 1.3.0 #11918

Closed

Description

@pllim

pandas 1.3.0 was released 3 hours ago (as of writing this): https://github.com/pandas-dev/pandas/releases/tag/v1.3.0

It is causing the following test failures. I think we can just update the test results, but I want to make sure that subpackage maintainers are fine with this plan. Doctest is trickier but we can just require pandas>=1.3 for those?

________________ [doctest] astropy.table.table.Table.to_pandas _________________
3572 
3573           >>> q = [1, 2] * u.m
3574           >>> tm = Time([1998, 2002], format='jyear')
3575           >>> sc = SkyCoord([5, 6], [7, 8], unit='deg')
3576           >>> dt = TimeDelta([3, 200] * u.s)
3577 
3578           >>> t = QTable([q, tm, sc, dt], names=['q', 'tm', 'sc', 'dt'])
3579 
3580           >>> df = t.to_pandas(index='tm')
3581           >>> with pd.option_context('display.max_columns', 20):
Differences (unified diff with -expected +actual):
    @@ -1,4 +1,3 @@
                   q  sc.ra  sc.dec              dt
    -tm
     1998-01-01  1.0    5.0     7.0 0 days 00:00:03
     2002-01-01  2.0    6.0     8.0 0 days 00:03:20

/Users/runner/work/astropy/astropy/.tox/py37-test-alldeps/lib/python3.7/site-packages/astropy/table/table.py:3581: DocTestFailure
______________________ TestPandas.test_from_pandas_index _______________________

self = <astropy.table.tests.test_table.TestPandas object at 0x1346a5390>

    def test_from_pandas_index(self):
        tm = Time([1998, 2002], format='jyear')
        x = [1, 2]
        t = table.Table([tm, x], names=['tm', 'x'])
        tp = t.to_pandas(index='tm')
    
        t2 = table.Table.from_pandas(tp)
        assert t2.colnames == ['x']
    
        t2 = table.Table.from_pandas(tp, index=True)
>       assert t2.colnames == ['tm', 'x']
E       AssertionError: assert ['index', 'x'] == ['tm', 'x']
E         At index 0 diff: 'index' != 'tm'
E         Use -v to get the full diff

../../.tox/py37-test-alldeps/lib/python3.7/site-packages/astropy/table/tests/test_table.py:1961: AssertionError
_____________________________ [doctest] pandas.rst _____________________________
059     2015-07-06T00:00:00.000000000     3
060 
061 Converting to :class:`~pandas.DataFrame` can also be done with
062 :meth:`~astropy.timeseries.TimeSeries.to_pandas`:
063 
064 .. doctest-requires:: pandas
065 
066     >>> ts['b'] = [1.2, 3.4, 5.4]
067     >>> df_new = ts.to_pandas()
068     >>> df_new
Differences (unified diff with -expected +actual):
    @@ -1,4 +1,3 @@
                 a    b
    -time
     2015-07-04  1  1.2
     2015-07-05  2  3.4

/Users/runner/work/astropy/astropy/docs/timeseries/pandas.rst:68: DocTestFailure

Example log with pandas 1.3.0 (failed): https://github.com/astropy/astropy/runs/2973199416?check_suite_focus=true

Example log with pandas 1.2.5 (passed): https://github.com/astropy/astropy/runs/2968371046?check_suite_focus=true

Activity

  1. mhvk commented on Jul 2, 2021

    @mhvk
    Contributor

    It seems strange that the name of the index column is lost, so not sure just updating the test is OK. But I don't understand pandas well enough to know...

  2. pllim commented on Jul 2, 2021

    @pllim
    MemberAuthor

    Yeah... Perhaps @taldcroft could advise or if not, maybe ping someone from pandas to make sure this change is intentional.

  3. pllim commented on Jul 2, 2021

    @pllim
    MemberAuthor

    I wanted to test this locally but pip install pandas -U refuses to upgrade from 1.2.x to 1.3 on Python 3.9. 🤯

  4. taldcroft commented on Jul 3, 2021

    @taldcroft
    Member

    Hopefully fixed by #11921.

  5. taldcroft commented on Jul 3, 2021

    @taldcroft
    Member

    p.s. I use conda and conda install -c conda-forge pandas=1.3.0 worked for me.

  6. taldcroft commented on Jul 3, 2021

    @taldcroft
    Member

    It seems strange that the name of the index column is lost

    The problem is actually in to_pandas(), and I'm surprised that this was previously working. Pandas was noticing that the index being set (an astropy Column) had a name attribute, even though it presumably knows nothing about astropy Column.

  7. pllim commented on Jul 4, 2021

    @pllim
    MemberAuthor

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions