예제 #1
0
    def test_headers_merging_right(self, _tfs_file_x_pathlib,
                                   _tfs_file_y_pathlib, how):
        headers_left = tfs.read(_tfs_file_x_pathlib).headers
        headers_right = tfs.read(_tfs_file_y_pathlib).headers
        result = merge_headers(headers_left, headers_right, how=how)

        assert isinstance(result, OrderedDict)
        assert len(result) >= len(headers_left) and len(result) >= len(
            headers_right)  # no key disappeared
        for key in result:  # check that we prioritized headers_right's contents
            if key in headers_left and key in headers_right:
                assert result[key] == headers_right[key]
예제 #2
0
    def test_correct_appending(self, _tfs_file_x_pathlib, _tfs_file_y_pathlib,
                               how_headers):
        dframe_x = tfs.read(_tfs_file_x_pathlib)
        dframe_y = tfs.read(_tfs_file_y_pathlib)
        result = dframe_x.append(dframe_y, how_headers=how_headers)

        assert isinstance(result, TfsDataFrame)
        assert isinstance(result.headers, OrderedDict)
        assert_dict_equal(
            result.headers,
            merge_headers(dframe_x.headers, dframe_y.headers, how=how_headers))
        assert_frame_equal(
            result,
            pd.DataFrame(dframe_x).append(pd.DataFrame(dframe_y)))
예제 #3
0
    def test_appending_accepts_pandas_dataframe(self, _tfs_file_x_pathlib,
                                                _tfs_file_y_pathlib,
                                                how_headers):
        dframe_x = tfs.read(_tfs_file_x_pathlib)
        dframe_y = pd.DataFrame(
            tfs.read(_tfs_file_y_pathlib))  # for test, loses headers here
        result = dframe_x.append(dframe_y, how_headers=how_headers)

        assert isinstance(result, TfsDataFrame)
        assert isinstance(result.headers, OrderedDict)

        # using empty OrderedDict here as it's what dframe_y is getting when converted in the call
        assert_dict_equal(
            result.headers,
            merge_headers(dframe_x.headers, OrderedDict(), how=how_headers))
        assert_frame_equal(
            result,
            pd.DataFrame(dframe_x).append(dframe_y))  # dframe_y already pandas
예제 #4
0
    def test_correct_joining(self, _tfs_file_x_pathlib, _tfs_file_y_pathlib,
                             how_headers, lsuffix, rsuffix):
        dframe_x = tfs.read(_tfs_file_x_pathlib)
        dframe_y = tfs.read(_tfs_file_y_pathlib)
        result = dframe_x.join(dframe_y,
                               how_headers=how_headers,
                               lsuffix=lsuffix,
                               rsuffix=rsuffix)

        assert isinstance(result, TfsDataFrame)
        assert isinstance(result.headers, OrderedDict)
        assert_dict_equal(
            result.headers,
            merge_headers(dframe_x.headers, dframe_y.headers, how=how_headers))
        assert_frame_equal(
            result,
            pd.DataFrame(dframe_x).join(pd.DataFrame(dframe_y),
                                        lsuffix=lsuffix,
                                        rsuffix=rsuffix))
예제 #5
0
 def test_headers_merging_none_returns_empty_dict(self, _tfs_file_x_pathlib,
                                                  _tfs_file_y_pathlib, how):
     headers_left = tfs.read(_tfs_file_x_pathlib).headers
     headers_right = tfs.read(_tfs_file_y_pathlib).headers
     result = merge_headers(headers_left, headers_right, how=how)
     assert result == OrderedDict()  # giving None returns empty headers
예제 #6
0
    def test_merge_headers_raises_on_invalid_how_key(self, caplog, how):
        headers_left = OrderedDict()
        headers_right = OrderedDict()

        with pytest.raises(ValueError):
            merge_headers(headers_left, headers_right, how=how)