當前位置: 首頁>>代碼示例>>Python>>正文


Python merge.MergeError方法代碼示例

本文整理匯總了Python中pandas.core.reshape.merge.MergeError方法的典型用法代碼示例。如果您正苦於以下問題:Python merge.MergeError方法的具體用法?Python merge.MergeError怎麽用?Python merge.MergeError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.core.reshape.merge的用法示例。


在下文中一共展示了merge.MergeError方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_merge_misspecified

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_merge_misspecified(self):
        msg = "Must pass right_on or right_index=True"
        with pytest.raises(pd.errors.MergeError, match=msg):
            merge(self.left, self.right, left_index=True)
        msg = "Must pass left_on or left_index=True"
        with pytest.raises(pd.errors.MergeError, match=msg):
            merge(self.left, self.right, right_index=True)

        msg = ('Can only pass argument "on" OR "left_on" and "right_on", not'
               ' a combination of both')
        with pytest.raises(pd.errors.MergeError, match=msg):
            merge(self.left, self.left, left_on='key', on='key')

        msg = r"len\(right_on\) must equal len\(left_on\)"
        with pytest.raises(ValueError, match=msg):
            merge(self.df, self.df2, left_on=['key1'],
                  right_on=['key1', 'key2']) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_merge.py

示例2: test_overlapping_columns_error_message

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_overlapping_columns_error_message(self):
        df = DataFrame({'key': [1, 2, 3],
                        'v1': [4, 5, 6],
                        'v2': [7, 8, 9]})
        df2 = DataFrame({'key': [1, 2, 3],
                         'v1': [4, 5, 6],
                         'v2': [7, 8, 9]})

        df.columns = ['key', 'foo', 'foo']
        df2.columns = ['key', 'bar', 'bar']
        expected = DataFrame({'key': [1, 2, 3],
                              'v1': [4, 5, 6],
                              'v2': [7, 8, 9],
                              'v3': [4, 5, 6],
                              'v4': [7, 8, 9]})
        expected.columns = ['key', 'foo', 'foo', 'bar', 'bar']
        assert_frame_equal(merge(df, df2), expected)

        # #2649, #10639
        df2.columns = ['key1', 'foo', 'foo']
        msg = (r"Data columns not unique: Index\(\[u?'foo', u?'foo'\],"
               r" dtype='object'\)")
        with pytest.raises(MergeError, match=msg):
            merge(df, df2) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:test_merge.py

示例3: test_multi_index

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_multi_index(self):

        # MultiIndex is prohibited
        trades = self.trades.set_index(['time', 'price'])
        quotes = self.quotes.set_index('time')
        with pytest.raises(MergeError):
            merge_asof(trades, quotes,
                       left_index=True,
                       right_index=True)

        trades = self.trades.set_index('time')
        quotes = self.quotes.set_index(['time', 'bid'])
        with pytest.raises(MergeError):
            merge_asof(trades, quotes,
                       left_index=True,
                       right_index=True) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_merge_asof.py

示例4: test_on_and_index

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_on_and_index(self):

        # 'on' parameter and index together is prohibited
        trades = self.trades.set_index('time')
        quotes = self.quotes.set_index('time')
        with pytest.raises(MergeError):
            merge_asof(trades, quotes,
                       left_on='price',
                       left_index=True,
                       right_index=True)

        trades = self.trades.set_index('time')
        quotes = self.quotes.set_index('time')
        with pytest.raises(MergeError):
            merge_asof(trades, quotes,
                       right_on='bid',
                       left_index=True,
                       right_index=True) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_merge_asof.py

示例5: test_valid_join_keys

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_valid_join_keys(self):

        trades = self.trades
        quotes = self.quotes

        with pytest.raises(MergeError):
            merge_asof(trades, quotes,
                       left_on='time',
                       right_on='bid',
                       by='ticker')

        with pytest.raises(MergeError):
            merge_asof(trades, quotes,
                       on=['time', 'ticker'],
                       by='ticker')

        with pytest.raises(MergeError):
            merge_asof(trades, quotes,
                       by='ticker') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_merge_asof.py

示例6: test_no_overlap_more_informative_error

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_no_overlap_more_informative_error(self):
        dt = datetime.now()
        df1 = DataFrame({'x': ['a']}, index=[dt])

        df2 = DataFrame({'y': ['b', 'c']}, index=[dt, dt])

        msg = ('No common columns to perform merge on. '
               'Merge options: left_on={lon}, right_on={ron}, '
               'left_index={lidx}, right_index={ridx}'
               .format(lon=None, ron=None, lidx=False, ridx=False))

        with pytest.raises(MergeError, match=msg):
            merge(df1, df2) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:test_merge.py

示例7: test_valid_allow_exact_matches

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_valid_allow_exact_matches(self):

        trades = self.trades
        quotes = self.quotes

        with pytest.raises(MergeError):
            merge_asof(trades, quotes,
                       on='time',
                       by='ticker',
                       allow_exact_matches='foo') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_merge_asof.py

示例8: test_merge_datatype_error

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_merge_datatype_error(self):
        """ Tests merge datatype mismatch error """
        msg = r'merge keys \[0\] object and int64, must be the same type'

        left = pd.DataFrame({'left_val': [1, 5, 10],
                             'a': ['a', 'b', 'c']})
        right = pd.DataFrame({'right_val': [1, 2, 3, 6, 7],
                              'a': [1, 2, 3, 6, 7]})

        with pytest.raises(MergeError, match=msg):
            merge_asof(left, right, on='a') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:13,代碼來源:test_merge_asof.py

示例9: test_no_overlap_more_informative_error

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_no_overlap_more_informative_error(self):
        dt = datetime.now()
        df1 = DataFrame({'x': ['a']}, index=[dt])

        df2 = DataFrame({'y': ['b', 'c']}, index=[dt, dt])
        pytest.raises(MergeError, merge, df1, df2)

        msg = ('No common columns to perform merge on. '
               'Merge options: left_on={lon}, right_on={ron}, '
               'left_index={lidx}, right_index={ridx}'
               .format(lon=None, ron=None, lidx=False, ridx=False))

        with tm.assert_raises_regex(MergeError, msg):
            merge(df1, df2) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:16,代碼來源:test_merge.py

示例10: test_multiby_indexed

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_multiby_indexed(self):
        # GH15676
        left = pd.DataFrame([
            [pd.to_datetime('20160602'), 1, 'a'],
            [pd.to_datetime('20160602'), 2, 'a'],
            [pd.to_datetime('20160603'), 1, 'b'],
            [pd.to_datetime('20160603'), 2, 'b']],
            columns=['time', 'k1', 'k2']).set_index('time')

        right = pd.DataFrame([
            [pd.to_datetime('20160502'), 1, 'a', 1.0],
            [pd.to_datetime('20160502'), 2, 'a', 2.0],
            [pd.to_datetime('20160503'), 1, 'b', 3.0],
            [pd.to_datetime('20160503'), 2, 'b', 4.0]],
            columns=['time', 'k1', 'k2', 'value']).set_index('time')

        expected = pd.DataFrame([
            [pd.to_datetime('20160602'), 1, 'a', 1.0],
            [pd.to_datetime('20160602'), 2, 'a', 2.0],
            [pd.to_datetime('20160603'), 1, 'b', 3.0],
            [pd.to_datetime('20160603'), 2, 'b', 4.0]],
            columns=['time', 'k1', 'k2', 'value']).set_index('time')

        result = pd.merge_asof(left,
                               right,
                               left_index=True,
                               right_index=True,
                               by=['k1', 'k2'])

        assert_frame_equal(expected, result)

        with pytest.raises(MergeError):
            pd.merge_asof(left, right, left_index=True, right_index=True,
                          left_by=['k1', 'k2'], right_by=['k1']) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:36,代碼來源:test_merge_asof.py

示例11: test_on_specialized_type

# 需要導入模塊: from pandas.core.reshape import merge [as 別名]
# 或者: from pandas.core.reshape.merge import MergeError [as 別名]
def test_on_specialized_type(self):
        # GH13936
        for dtype in [np.uint8, np.uint16, np.uint32, np.uint64,
                      np.int8, np.int16, np.int32, np.int64,
                      np.float16, np.float32, np.float64]:
            df1 = pd.DataFrame({
                'value': [5, 2, 25, 100, 78, 120, 79],
                'symbol': list("ABCDEFG")},
                columns=['symbol', 'value'])
            df1.value = dtype(df1.value)

            df2 = pd.DataFrame({
                'value': [0, 80, 120, 125],
                'result': list('xyzw')},
                columns=['value', 'result'])
            df2.value = dtype(df2.value)

            df1 = df1.sort_values('value').reset_index(drop=True)

            if dtype == np.float16:
                with pytest.raises(MergeError):
                    pd.merge_asof(df1, df2, on='value')
                continue

            result = pd.merge_asof(df1, df2, on='value')

            expected = pd.DataFrame(
                {'symbol': list("BACEGDF"),
                 'value': [2, 5, 25, 78, 79, 100, 120],
                 'result': list('xxxxxyz')
                 }, columns=['symbol', 'value', 'result'])
            expected.value = dtype(expected.value)

            assert_frame_equal(result, expected) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:36,代碼來源:test_merge_asof.py


注:本文中的pandas.core.reshape.merge.MergeError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。