コード例 #1
0
ファイル: test_merge.py プロジェクト: andreas-h/pandas
    def test_basic(self):
        result = ordered_merge(self.left, self.right, on='key')
        expected = DataFrame({'key': ['a', 'b', 'c', 'd', 'e', 'f'],
                              'lvalue': [1, nan, 2, nan, 3, nan],
                              'rvalue': [nan, 1, 2, 3, nan, 4]})

        assert_frame_equal(result, expected)
コード例 #2
0
ファイル: test_merge.py プロジェクト: edmoody/pandas
    def test_basic(self):
        result = ordered_merge(self.left, self.right, on="key")
        expected = DataFrame(
            {
                "key": ["a", "b", "c", "d", "e", "f"],
                "lvalue": [1, nan, 2, nan, 3, nan],
                "rvalue": [nan, 1, 2, 3, nan, 4],
            }
        )

        assert_frame_equal(result, expected)
コード例 #3
0
ファイル: test_merge.py プロジェクト: andreas-h/pandas
    def test_multigroup(self):
        left = concat([self.left, self.left], ignore_index=True)
        # right = concat([self.right, self.right], ignore_index=True)

        left['group'] = ['a'] * 3 + ['b'] * 3
        # right['group'] = ['a'] * 4 + ['b'] * 4

        result = ordered_merge(left, self.right, on='key', left_by='group',
                               fill_method='ffill')
        expected = DataFrame({'key': ['a', 'b', 'c', 'd', 'e', 'f'] * 2,
                              'lvalue': [1., 1, 2, 2, 3, 3.] * 2,
                              'rvalue': [nan, 1, 2, 3, 3, 4] * 2})
        expected['group'] = ['a'] * 6 + ['b'] * 6

        assert_frame_equal(result, expected.ix[:, result.columns])

        result2 = ordered_merge(self.right, left, on='key', right_by='group',
                                fill_method='ffill')
        assert_frame_equal(result, result2.ix[:, result.columns])

        result = ordered_merge(left, self.right, on='key', left_by='group')
        self.assert_(result['group'].notnull().all())
コード例 #4
0
ファイル: test_merge.py プロジェクト: edmoody/pandas
    def test_multigroup(self):
        left = concat([self.left, self.left], ignore_index=True)
        # right = concat([self.right, self.right], ignore_index=True)

        left["group"] = ["a"] * 3 + ["b"] * 3
        # right['group'] = ['a'] * 4 + ['b'] * 4

        result = ordered_merge(left, self.right, on="key", left_by="group", fill_method="ffill")
        expected = DataFrame(
            {
                "key": ["a", "b", "c", "d", "e", "f"] * 2,
                "lvalue": [1.0, 1, 2, 2, 3, 3.0] * 2,
                "rvalue": [nan, 1, 2, 3, 3, 4] * 2,
            }
        )
        expected["group"] = ["a"] * 6 + ["b"] * 6

        assert_frame_equal(result, expected.ix[:, result.columns])

        result2 = ordered_merge(self.right, left, on="key", right_by="group", fill_method="ffill")
        assert_frame_equal(result, result2.ix[:, result.columns])

        result = ordered_merge(left, self.right, on="key", left_by="group")
        self.assert_(result["group"].notnull().all())
コード例 #5
0
ファイル: test_merge.py プロジェクト: andreas-h/pandas
 def test_ffill(self):
     result = ordered_merge(self.left, self.right, on='key', fill_method='ffill')
     expected = DataFrame({'key': ['a', 'b', 'c', 'd', 'e', 'f'],
                           'lvalue': [1., 1, 2, 2, 3, 3.],
                           'rvalue': [nan, 1, 2, 3, 3, 4]})
     assert_frame_equal(result, expected)
コード例 #6
0
ファイル: test_merge.py プロジェクト: edmoody/pandas
 def test_ffill(self):
     result = ordered_merge(self.left, self.right, on="key", fill_method="ffill")
     expected = DataFrame(
         {"key": ["a", "b", "c", "d", "e", "f"], "lvalue": [1.0, 1, 2, 2, 3, 3.0], "rvalue": [nan, 1, 2, 3, 3, 4]}
     )
     assert_frame_equal(result, expected)