Python pandas.core.reshape.merge.MergeError() Examples
The following are 30
code examples of pandas.core.reshape.merge.MergeError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.core.reshape.merge
, or try the search function
.
Example #1
Source File: test_merge_asof.py From vnpy_crypto with MIT License | 6 votes |
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')
Example #2
Source File: test_merge.py From recruit with Apache License 2.0 | 6 votes |
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'])
Example #3
Source File: test_merge_asof.py From coffeegrindsize with MIT License | 6 votes |
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)
Example #4
Source File: test_merge_asof.py From coffeegrindsize with MIT License | 6 votes |
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)
Example #5
Source File: test_merge_asof.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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')
Example #6
Source File: test_merge_asof.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: test_merge_asof.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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)
Example #8
Source File: test_merge.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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)
Example #9
Source File: test_merge_asof.py From coffeegrindsize with MIT License | 6 votes |
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')
Example #10
Source File: test_merge.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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'])
Example #11
Source File: test_merge.py From coffeegrindsize with MIT License | 6 votes |
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)
Example #12
Source File: test_merge_asof.py From elasticintel with GNU General Public License v3.0 | 6 votes |
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)
Example #13
Source File: test_merge_asof.py From elasticintel with GNU General Public License v3.0 | 6 votes |
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)
Example #14
Source File: test_merge_asof.py From twitter-stock-recommendation with MIT License | 6 votes |
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)
Example #15
Source File: test_merge_asof.py From twitter-stock-recommendation with MIT License | 6 votes |
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)
Example #16
Source File: test_merge_asof.py From vnpy_crypto with MIT License | 6 votes |
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)
Example #17
Source File: test_merge_asof.py From vnpy_crypto with MIT License | 6 votes |
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)
Example #18
Source File: test_merge_asof.py From twitter-stock-recommendation with MIT License | 6 votes |
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')
Example #19
Source File: test_merge_asof.py From elasticintel with GNU General Public License v3.0 | 6 votes |
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')
Example #20
Source File: test_merge.py From coffeegrindsize with MIT License | 6 votes |
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'])
Example #21
Source File: test_merge_asof.py From recruit with Apache License 2.0 | 6 votes |
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')
Example #22
Source File: test_merge_asof.py From recruit with Apache License 2.0 | 6 votes |
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)
Example #23
Source File: test_merge_asof.py From recruit with Apache License 2.0 | 6 votes |
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)
Example #24
Source File: test_merge.py From recruit with Apache License 2.0 | 6 votes |
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)
Example #25
Source File: test_merge_asof.py From coffeegrindsize with MIT License | 5 votes |
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')
Example #26
Source File: test_merge.py From coffeegrindsize with MIT License | 5 votes |
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)
Example #27
Source File: test_merge_asof.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_on_specialized_type_by_int(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], 'key': [1, 2, 3, 2, 3, 1, 2], 'symbol': list("ABCDEFG")}, columns=['symbol', 'key', 'value']) df1.value = dtype(df1.value) df2 = pd.DataFrame({ 'value': [0, 80, 120, 125], 'key': [1, 2, 2, 3], 'result': list('xyzw')}, columns=['value', 'key', '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', by='key') else: result = pd.merge_asof(df1, df2, on='value', by='key') expected = pd.DataFrame({ 'symbol': list("BACEGDF"), 'key': [2, 1, 3, 3, 2, 2, 1], 'value': [2, 5, 25, 78, 79, 100, 120], 'result': [np.nan, 'x', np.nan, np.nan, np.nan, 'y', 'x']}, columns=['symbol', 'key', 'value', 'result']) expected.value = dtype(expected.value) assert_frame_equal(result, expected)
Example #28
Source File: test_merge_asof.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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')
Example #29
Source File: test_merge_asof.py From coffeegrindsize with MIT License | 5 votes |
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')
Example #30
Source File: test_merge.py From twitter-stock-recommendation with MIT License | 5 votes |
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)