trackintel icon indicating copy to clipboard operation
trackintel copied to clipboard

TestPfsMeanSpeedTriplegs.test_triplegs_stable is failing!

Open henrymartin1 opened this issue 2 years ago • 0 comments

It seems that Geopandas changed something and now the labels of the index are not correct anymore:

E       AssertionError: GeoDataFrame.index are different
E       
E       Attribute "names" are different
E       [left]:  ['id']
E       [right]: [None]

here is the full log from the consol

=================================== FAILURES ===================================
________________ TestPfsMeanSpeedTriplegs.test_triplegs_stable _________________

self = <tests.model.test_util.TestPfsMeanSpeedTriplegs object at 0x7f0595467d00>
example_triplegs = (      elevation                tracked_at  ... staypoint_id  tripleg_id
id                                         .....39.97814, 116.32681 39.9...
21        1  ...  LINESTRING (116.31188 39.98228, 116.31203 39.9...

[22 rows x 4 columns])

    def test_triplegs_stable(self, example_triplegs):
        """Test whether the triplegs stay the same apart from the new speed column"""
        pfs, tpls = example_triplegs
        tpls_speed = ti.model.util.get_speed_triplegs(tpls, pfs, method="pfs_mean_speed")
>       assert_geodataframe_equal(tpls, tpls_speed.drop(columns=["speed"]))

tests/model/test_util.py:106: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

left =     user_id  ...                                               geom
id           ...                                  ... 39.97814, 116.32681 39.9...
21        1  ...  LINESTRING (116.31188 39.98228, 116.31203 39.9...

[22 rows x 4 columns]
right =     user_id  ...                                               geom
0         0  ...  LINESTRING (116.31842 39.98470, ... 39.97814, 116.32681 39.9...
21        1  ...  LINESTRING (116.31188 39.98228, 116.31203 39.9...

[22 rows x 4 columns]
check_dtype = True, check_index_type = 'equiv', check_column_type = 'equiv'
check_frame_type = True, check_like = False, check_less_precise = False
check_geom_type = False, check_crs = True, normalize = False

    def assert_geodataframe_equal(
        left,
        right,
        check_dtype=True,
        check_index_type="equiv",
        check_column_type="equiv",
        check_frame_type=True,
        check_like=False,
        check_less_precise=False,
        check_geom_type=False,
        check_crs=True,
        normalize=False,
    ):
        """
        Check that two GeoDataFrames are equal/
    
        Parameters
        ----------
        left, right : two GeoDataFrames
        check_dtype : bool, default True
            Whether to check the DataFrame dtype is identical.
        check_index_type, check_column_type : bool, default 'equiv'
            Check that index types are equal.
        check_frame_type : bool, default True
            Check that both are same type (*and* are GeoDataFrames). If False,
            will attempt to convert both into GeoDataFrame.
        check_like : bool, default False
            If true, ignore the order of rows & columns
        check_less_precise : bool, default False
            If True, use geom_almost_equals. if False, use geom_equals.
        check_geom_type : bool, default False
            If True, check that all the geom types are equal.
        check_crs: bool, default True
            If `check_frame_type` is True, then also check that the
            crs matches.
        normalize: bool, default False
            If True, normalize the geometries before comparing equality.
            Typically useful with ``check_less_precise=True``, which uses
            ``geom_almost_equals`` and requires exact coordinate order.
        """
        try:
            # added from pandas 0.20
            from pandas.testing import assert_frame_equal, assert_index_equal
        except ImportError:
            from pandas.util.testing import assert_frame_equal, assert_index_equal
    
        # instance validation
        if check_frame_type:
            assert isinstance(left, GeoDataFrame)
            assert isinstance(left, type(right))
    
            if check_crs:
                # no crs can be either None or {}
                if not left.crs and not right.crs:
                    pass
                else:
                    assert left.crs == right.crs
        else:
            if not isinstance(left, GeoDataFrame):
                left = GeoDataFrame(left)
            if not isinstance(right, GeoDataFrame):
                right = GeoDataFrame(right)
    
        # shape comparison
        assert left.shape == right.shape, (
            "GeoDataFrame shape mismatch, left: {lshape!r}, right: {rshape!r}.\n"
            "Left columns: {lcols!r}, right columns: {rcols!r}"
        ).format(
            lshape=left.shape, rshape=right.shape, lcols=left.columns, rcols=right.columns
        )
    
        if check_like:
            left, right = left.reindex_like(right), right
    
        # column comparison
        assert_index_equal(
            left.columns, right.columns, exact=check_column_type, obj="GeoDataFrame.columns"
        )
    
        # geometry comparison
        for col, dtype in left.dtypes.items():
            if isinstance(dtype, GeometryDtype):
                assert_geoseries_equal(
                    left[col],
                    right[col],
                    normalize=normalize,
                    check_dtype=check_dtype,
                    check_less_precise=check_less_precise,
                    check_geom_type=check_geom_type,
                    check_crs=check_crs,
                )
    
        # drop geometries and check remaining columns
        left2 = left.drop([left._geometry_column_name], axis=1)
        right2 = right.drop([right._geometry_column_name], axis=1)
>       assert_frame_equal(
            left2,
            right2,
            check_dtype=check_dtype,
            check_index_type=check_index_type,
            check_column_type=check_column_type,
            obj="GeoDataFrame",
        )
E       AssertionError: GeoDataFrame.index are different
E       
E       Attribute "names" are different
E       [left]:  ['id']
E       [right]: [None]

/usr/share/miniconda3/envs/test/lib/python3.9/site-packages/geopandas/testing.py:334: AssertionError

henrymartin1 avatar Sep 28 '22 12:09 henrymartin1