threeML / astromodels

Spatial and spectral models for astrophysics
BSD 3-Clause "New" or "Revised" License
44 stars 45 forks source link

Test error with pandas 1.1.0 #128

Closed ndilalla closed 4 years ago

ndilalla commented 4 years ago

Astromodels seems to be not compatible with the last version of pandas (1.1.0) released few weeks ago. This is the detail of the test_template_factory_1D failure:

___________________________ test_template_factory_1D ___________________________

    @pytest.mark.slow
    def test_template_factory_1D():
        mo = get_comparison_function()
        energies = np.logspace(1, 3, 50)

        t = TemplateModelFactory('__test1D', 'A test template', energies, ['alpha'])
        alpha_grid = np.linspace(-1.5, 1, 15)
        #beta_grid = np.linspace(-3.5, -1.6, 15)
        #xp_grid = np.logspace(1, 3, 20)

        t.define_parameter_grid('alpha', alpha_grid)

        for a in alpha_grid:
            mo.alpha = a
            mo.beta = -2.5
            mo.xp = 300.    
>          t.add_interpolation_data(mo(energies), alpha=a)

test_template_model.py:47: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

../../../miniconda/envs/test_env/lib/python3.7/site-packages/astromodels/functions/template_model.py:232: in add_interpolation_data
    differential_fluxes)
../../../miniconda/envs/test_env/lib/python3.7/site-packages/pandas/core/indexing.py:666: in __setitem__
    indexer = self._get_setitem_indexer(key)
../../../miniconda/envs/test_env/lib/python3.7/site-packages/pandas/core/indexing.py:593: in _get_setitem_indexer
    self._ensure_listlike_indexer(key)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pandas.core.indexing._LocIndexer object at 0x7fee12d9b9f8>
key = (-1.5,), axis = None
    def _ensure_listlike_indexer(self, key, axis=None):
        """
        Ensure that a list-like of column labels are all present by adding them if
        they do not already exist.

        Parameters
        ----------
        key : list-like of column labels
            Target labels.
        axis : key axis if known
        """
        column_axis = 1

        # column only exists in 2-dimensional DataFrame
        if self.ndim != 2:
            return

        if isinstance(key, tuple):
            # key may be a tuple if we are .loc
            # in that case, set key to the column part of key
>           key = key[column_axis]
E           IndexError: tuple index out of range

../../../miniconda/envs/test_env/lib/python3.7/site-packages/pandas/core/indexing.py:647: IndexError
ndilalla commented 4 years ago

For the moment, as a workaround, I am pinning the pandas version < 1.1

grburgess commented 4 years ago

Thanks, I'm still having an issue completely reproducing the original structure... will need a day or two more.

grburgess commented 4 years ago

fixed in #129