def test_indexing_series_iloc_set(self): v1 = [1, 2, 3, 4, 5] v2 = ["a", "b", "c", "d", "e"] ps = pd.Series(v1, index=list(range(0, 10, 2))) os = orca.Series(v1, index=list(range(0, 10, 2))) ps.iloc[:3] = 4 os.iloc[:3] = 4 assert_series_equal(os.to_pandas(), ps) ps = pd.Series(v2, index=list(range(0, 10, 2))) os = orca.Series(v2, index=list(range(0, 10, 2))) ps.iloc[:3] = "s" os.iloc[:3] = "s" assert_series_equal(os.to_pandas(), ps) ps = pd.Series(v1, index=["a", "a", "b", "b", "c"]) os = orca.Series(v1, index=["a", "a", "b", "b", "c"]) ps.iloc[:3] = 4 os.iloc[:3] = 4 assert_series_equal(os.to_pandas(), ps) ps = pd.Series(v2, index=["a", "a", "b", "b", "c"]) os = orca.Series(v2, index=["a", "a", "b", "b", "c"]) ps.iloc[:3] = "s" os.iloc[:3] = "s" assert_series_equal(os.to_pandas(), ps)
def test_series_concat(self): s1 = pd.Series(['a', 'b']) s2 = pd.Series(['c', 'd']) o1 = orca.Series(['a', 'b']) o2 = orca.Series(['c', 'd']) assert_series_equal(pd.concat([s1, s2]), orca.concat([o1, o2]).to_pandas()) assert_series_equal( pd.concat([s1, s2], ignore_index=True), orca.concat([o1, o2], ignore_index=True).to_pandas())
def test_dataframe(self): odf = self.odf pdf = self.pdf self.assertEqual(repr((odf['a'] + 1).to_pandas()), repr(pdf['a'] + 1)) self.assertEqual(repr(odf.columns), repr(pd.Index(['a', 'b']))) self.assertEqual(repr((odf[odf['b'] > 2]).to_pandas()), repr(pdf[pdf['b'] > 2])) self.assertEqual(repr(odf[['a', 'b']]), repr(pdf[['a', 'b']])) self.assertEqual(repr(odf.a), repr(pdf.a)) assert repr(odf) df = pd.DataFrame({ 'a': [1, 2, 3, 4, 5, 6, 7, 8, 9], 'b': [4, 5, 6, 3, 2, 1, 0, 0, 0], }) ddf = orca.DataFrame(df) self.assertEqual(repr(df[['a', 'b']]), repr(ddf[['a', 'b']])) # TODO:NOT IMPLEMENTED # self.assertEqual(repr(ddf.a.notnull().alias("x").name), repr("x")) # check orca.DataFrame(os.Series) pser = pd.Series([1, 2, 3], name='x') kser = orca.Series([1, 2, 3], name='x') self.assertEqual(repr(pd.DataFrame(pser)), repr(orca.DataFrame(kser)))
def test_indexing_series_loc_set(self): ps = pd.Series(list('abcde'), index=[0, 3, 2, 5, 4]) os = orca.Series(list('abcde'), index=[0, 3, 2, 5, 4]) assert_series_equal(os.to_pandas(), ps) ps.loc[3:5] = "5" os.loc[3:5] = "5" assert_series_equal(os.to_pandas(), ps) ps = pd.Series(np.repeat(1, 5), index=[0, 3, 2, 5, 4]) os = orca.Series(np.repeat(1, 5), index=[0, 3, 2, 5, 4]) ps.loc[3:5] = 2 os.loc[3:5] = 2 assert_series_equal(os.to_pandas(), ps) ps = pd.Series(list('abcde'), index=["a", "a", "a", "b", "b"]) os = orca.Series(list('abcde'), index=["a", "a", "a", "b", "b"]) assert_series_equal(os.to_pandas(), ps) ps.loc["a"] = "5" os.loc["a"] = "5" assert_series_equal(os.to_pandas(), ps)
def test_indexing_series_sort_index(self): ps = pd.Series(list('abcde'), index=[0, 3, 2, 5, 4]) os = orca.Series(list('abcde'), index=[0, 3, 2, 5, 4]) assert_series_equal(ps.sort_index(), os.sort_index().to_pandas()) assert_series_equal(ps.sort_index().loc[0:3], os.sort_index().loc[0:3].to_pandas())
def test_indexing_series_iloc_get(self): v = [1, 2, 3, 4, 5] ps = pd.Series(v, index=list(range(0, 10, 2))) os = orca.Series(v, index=list(range(0, 10, 2))) assert_series_equal(os.iloc[:3].to_pandas(), ps.iloc[:3])
def test_indexing_series_loc_get(self): ps = pd.Series(list('abcde'), index=[0, 3, 2, 5, 4]) os = orca.Series(list('abcde'), index=[0, 3, 2, 5, 4]) assert_series_equal(ps, os.to_pandas()) assert_series_equal(os.loc[3:5].to_pandas(), ps.loc[3:5])
def test_indexing_dataframe_iloc_set(self): pdf = pd.DataFrame([{'a': 1, 'b': 2, 'c': 3, 'd': 4}, {'a': 100, 'b': 200, 'c': 300, 'd': 400}, {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000}]) odf = orca.DataFrame([{'a': 1, 'b': 2, 'c': 3, 'd': 4}, {'a': 100, 'b': 200, 'c': 300, 'd': 400}, {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000}]) # integer # iloc[*] pdf.iloc[0] = 11 odf.iloc[0] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0]] = 11 odf.iloc[[0]] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[1, 2]] = 110 odf.iloc[[1, 2]] = 110 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:] = 12 odf.iloc[1:] = 12 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2] = 12 odf.iloc[:2] = 12 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0:1] = 120 odf.iloc[0:1] = 120 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:] = 13 odf.iloc[:] = 13 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[True, False, True]] = 13 odf.iloc[[True, False, True]] = 13 assert_frame_equal(odf.to_pandas(), pdf) # iloc[0,*] pdf.iloc[0, 1] = 130 odf.iloc[0, 1] = 130 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0, [1]] = 11 odf.iloc[0, [1]] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0, [1, 3]] = 14 odf.iloc[0, [1, 3]] = 14 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0, 1:] = 140 odf.iloc[0, 1:] = 140 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0, :2] = 12 odf.iloc[0, :2] = 12 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0, 1:2] = 15 odf.iloc[0, 1:2] = 15 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0, 0] = 150 odf.iloc[0, 0] = 150 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0, [True, False, True, True]] = 13 odf.iloc[0, [True, False, True, True]] = 13 assert_frame_equal(odf.to_pandas(), pdf) # iloc[[0],*] pdf.iloc[0, 1] = 130 odf.iloc[0, 1] = 130 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0], [1]] = 11 odf.iloc[[0], [1]] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0], [1, 3]] = 14 odf.iloc[[0], [1, 3]] = 14 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0], 1:] = 140 odf.iloc[[0], 1:] = 140 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0], :2] = 12 odf.iloc[[0], :2] = 12 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0], 1:2] = 15 odf.iloc[[0], 1:2] = 15 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0], 0] = 150 odf.iloc[[0], 0] = 150 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0], [True, False, True, True]] = 13 odf.iloc[[0], [True, False, True, True]] = 13 assert_frame_equal(odf.to_pandas(), pdf) # iloc[[0,2],*] pdf.iloc[[0, 2], 1] = 130 odf.iloc[[0, 2], 1] = 130 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0, 2], [1]] = 11 odf.iloc[[0, 2], [1]] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0, 2], [1, 3]] = 14 odf.iloc[[0, 2], [1, 3]] = 14 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0, 2], 1:] = 140 odf.iloc[[0, 2], 1:] = 140 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0, 2], :2] = 12 odf.iloc[[0, 2], :2] = 12 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0, 2], 1:2] = 15 odf.iloc[[0, 2], 1:2] = 15 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0, 2], 0] = 150 odf.iloc[[0, 2], 0] = 150 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0, 2], [True, False, True, True]] = 13 odf.iloc[[0, 2], [True, False, True, True]] = 13 assert_frame_equal(odf.to_pandas(), pdf) # iloc[1:,*] pdf.iloc[1:, 1] = 130 odf.iloc[1:, 1] = 130 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:, [1]] = 11 odf.iloc[1:, [1]] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:, [1, 3]] = 14 odf.iloc[1:, [1, 3]] = 14 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:, 1:] = 140 odf.iloc[1:, 1:] = 140 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:, :2] = 12 odf.iloc[1:, :2] = 12 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:, 1:2] = 15 odf.iloc[1:, 1:2] = 15 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:, 0] = 150 odf.iloc[1:, 0] = 150 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:, [True, False, True, True]] = 13 odf.iloc[1:, [True, False, True, True]] = 13 assert_frame_equal(odf.to_pandas(), pdf) # iloc[:2,*] pdf.iloc[:2, 1] = 130 odf.iloc[:2, 1] = 130 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2, [1]] = 11 odf.iloc[:2, [1]] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2, [1, 3]] = 14 odf.iloc[:2, [1, 3]] = 14 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2, 1:2] = 140 odf.iloc[:2, 1:2] = 140 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2, :2] = 12 odf.iloc[:2, :2] = 12 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2, 1:2] = 15 odf.iloc[:2, 1:2] = 15 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2, 0] = 150 odf.iloc[:2, 0] = 150 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2, [True, False, True, True]] = 13 odf.iloc[:2, [True, False, True, True]] = 13 assert_frame_equal(odf.to_pandas(), pdf) # iloc[1:2,*] pdf.iloc[1:2, 1] = 130 odf.iloc[1:2, 1] = 130 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:2, [1]] = 11 odf.iloc[1:2, [1]] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:2, [1, 3]] = 14 odf.iloc[1:2, [1, 3]] = 14 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:2, 1:2] = 140 odf.iloc[1:2, 1:2] = 140 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:2, :2] = 12 odf.iloc[1:2, :2] = 12 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:2, 1:2] = 15 odf.iloc[1:2, 1:2] = 15 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:2, 0] = 150 odf.iloc[1:2, 0] = 150 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:2, [True, False, True, True]] = 13 odf.iloc[1:2, [True, False, True, True]] = 13 assert_frame_equal(odf.to_pandas(), pdf) # iloc[:,*] pdf.iloc[:, 1] = 130 odf.iloc[:, 1] = 130 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:, [1]] = 11 odf.iloc[:, [1]] = 11 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:, [1, 3]] = 14 odf.iloc[:, [1, 3]] = 14 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:, 1:] = 140 odf.iloc[:, 1:] = 140 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:, 1:2] = 15 odf.iloc[:, 1:2] = 15 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:, :] = 150 odf.iloc[:, :] = 150 assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:, [True, False, True, True]] = 13 odf.iloc[:, [True, False, True, True]] = 13 assert_frame_equal(odf.to_pandas(), pdf) # list array series dataframe pdf = pd.DataFrame([{'a': 1, 'b': 2, 'c': 3, 'd': 4}, {'a': 100, 'b': 200, 'c': 300, 'd': 400}, {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000}]) odf = orca.DataFrame([{'a': 1, 'b': 2, 'c': 3, 'd': 4}, {'a': 100, 'b': 200, 'c': 300, 'd': 400}, {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000}]) # iloc[*] pdf.iloc[0] = [1, 2, 1, 2] odf.iloc[0] = [1, 2, 1, 2] assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0] = np.array([1, 20, 10, 2]) odf.iloc[0] = np.array([1, 20, 10, 2]) assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0] = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']) odf.iloc[0] = orca.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']) assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0] = {'a': 0, 'b': 2, 'c': 2, 'd': 3} odf.iloc[0] = {'a': 0, 'b': 2, 'c': 2, 'd': 3} assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[0]] = pd.DataFrame({'a': 0, 'b': 2, 'c': 2, 'd': 3}, index=[0]) odf.iloc[[0]] = orca.DataFrame({'a': 0, 'b': 2, 'c': 2, 'd': 3}, index=[0]) assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[[1, 2]] = pd.DataFrame({'a': [0, 3], 'b': [0, 3], 'c': [0, 3], 'd': [0, 3]}, index=[1, 2]) odf.iloc[[1, 2]] = orca.DataFrame({'a': [0, 3], 'b': [0, 3], 'c': [0, 3], 'd': [0, 3]}, index=[1, 2]) assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[1:] = pd.DataFrame({'a': [0, 3], 'b': [0, 3], 'c': [0, 3], 'd': [0, 3]}, index=[1, 2]) odf.iloc[1:] = orca.DataFrame({'a': [0, 3], 'b': [0, 3], 'c': [0, 3], 'd': [0, 3]}, index=[1, 2]) assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[:2] = pd.DataFrame({'a': [0, 3], 'b': [0, 3], 'c': [0, 3], 'd': [0, 3]}, index=[0, 1]) odf.iloc[:2] = orca.DataFrame({'a': [0, 3], 'b': [0, 3], 'c': [0, 3], 'd': [0, 3]}, index=[0, 1]) assert_frame_equal(odf.to_pandas(), pdf) pdf.iloc[0:1] = pd.DataFrame({'a': 0, 'b': 2, 'c': 2, 'd': 3}, index=[0]) odf.iloc[0:1] = orca.DataFrame({'a': 0, 'b': 2, 'c': 2, 'd': 3}, index=[0]) assert_frame_equal(odf.to_pandas(), pdf)
def os(self): # return orca.Series(self.ps) return orca.Series([1, 2, 3, 4, 5, 6, 7], name='x')
def test_indexing_dataframe_loc_set(self): # scalar pdf = pd.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf = orca.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf.loc['cobra'] = 10 pdf.loc['cobra'] = 10 assert_frame_equal(odf.to_pandas(), pdf) odf.loc['cobra', 'shield'] = 10 pdf.loc['cobra', 'shield'] = 10 assert_frame_equal(odf.to_pandas(), pdf) odf.loc[['cobra', 'viper']] = 10 pdf.loc[['cobra', 'viper']] = 10 assert_frame_equal(odf.to_pandas(), pdf) odf.loc[[True, True, False]] = 10 pdf.loc[[True, True, False]] = 10 assert_frame_equal(odf.to_pandas(), pdf) odf.loc[odf['shield'] > 5] = 10 pdf.loc[pdf['shield'] > 5] = 10 assert_frame_equal(odf.to_pandas(), pdf) odf.loc[odf['shield'] > 6, ['max_speed']] = 10 pdf.loc[pdf['shield'] > 6, ['max_speed']] = 10 assert_frame_equal(odf.to_pandas(), pdf) odf.loc['cobra':'viper'] = 10 pdf.loc['cobra':'viper'] = 10 assert_frame_equal(odf.to_pandas(), pdf) odf.loc['cobra':'viper', 'max_speed'] = 10 pdf.loc['cobra':'viper', 'max_speed'] = 10 assert_frame_equal(odf.to_pandas(), pdf) odf.loc[:, 'max_speed'] = 10 pdf.loc[:, 'max_speed'] = 10 assert_frame_equal(odf.to_pandas(), pdf) # list pdf = pd.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf = orca.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf.loc['cobra'] = [10, 10] pdf.loc['cobra'] = [10, 10] assert_frame_equal(odf.to_pandas(), pdf) odf.loc[odf['shield'] > 5] = [9, 10] pdf.loc[pdf['shield'] > 5] = [9, 10] assert_frame_equal(odf.to_pandas(), pdf) odf.loc['cobra':'viper', 'max_speed'] = [11, 15] pdf.loc['cobra':'viper', 'max_speed'] = [11, 15] assert_frame_equal(odf.to_pandas(), pdf) odf.loc[:, 'max_speed'] = [10, 11, 12] pdf.loc[:, 'max_speed'] = [10, 11, 12] assert_frame_equal(odf.to_pandas(), pdf) # np.array pdf = pd.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf = orca.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf.loc['cobra'] = np.array([10, 12]) pdf.loc['cobra'] = np.array([10, 12]) assert_frame_equal(odf.to_pandas(), pdf) odf.loc['cobra', 'shield'] = np.array(10) pdf.loc['cobra', 'shield'] = np.array(10) assert_frame_equal(odf.to_pandas(), pdf) odf.loc[odf['shield'] > 6, ['max_speed']] = np.array(12) pdf.loc[pdf['shield'] > 6, ['max_speed']] = np.array(12) assert_frame_equal(odf.to_pandas(), pdf) odf.loc['cobra':'viper', 'max_speed'] = np.array([20, 30]) pdf.loc['cobra':'viper', 'max_speed'] = np.array([20, 30]) assert_frame_equal(odf.to_pandas(), pdf) odf.loc[:, 'max_speed'] = np.array([20, 30, 4]) pdf.loc[:, 'max_speed'] = np.array([20, 30, 4]) assert_frame_equal(odf.to_pandas(), pdf, check_dtype=False) # Series pdf = pd.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf = orca.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf.loc['cobra'] = orca.Series([10, 11], index=['max_speed', 'shield']) pdf.loc['cobra'] = pd.Series([10, 11], index=['max_speed', 'shield']) assert_frame_equal(odf.to_pandas(), pdf) odf.loc[odf['shield'] > 6, ['max_speed']] = orca.Series([12], index=['sidewinder']) pdf.loc[pdf['shield'] > 6, ['max_speed']] = pd.Series([12], index=['sidewinder']) assert_frame_equal(odf.to_pandas(), pdf, check_dtype=False) odf.loc['cobra':'viper', 'max_speed'] = orca.Series([12, 13], index=['cobra', 'viper']) pdf.loc['cobra':'viper', 'max_speed'] = pd.Series([12, 13], index=['cobra', 'viper']) assert_frame_equal(odf.to_pandas(), pdf, check_dtype=False) odf.loc[:, 'max_speed'] = orca.Series([12, 13, 14], index=['cobra', 'viper', 'sidewinder']) pdf.loc[:, 'max_speed'] = pd.Series([12, 13, 14], index=['cobra', 'viper', 'sidewinder']) assert_frame_equal(odf.to_pandas(), pdf, check_dtype=False) # Dict pdf = pd.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf = orca.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf.loc['cobra'] = {'max_speed': 11, 'shield': 12} pdf.loc['cobra'] = {'max_speed': 11, 'shield': 12} assert_frame_equal(odf.to_pandas(), pdf) odf.loc[odf['shield'] > 6, ['max_speed']] = {'sidewinder': 11} pdf.loc[pdf['shield'] > 6, ['max_speed']] = {'sidewinder': 11} assert_frame_equal(odf.to_pandas(), pdf, check_dtype=False) odf.loc['cobra':'viper', 'max_speed'] = {'cobra': 11, 'viper': 40} pdf.loc['cobra':'viper', 'max_speed'] = {'cobra': 11, 'viper': 40} assert_frame_equal(odf.to_pandas(), pdf, check_dtype=False) # DataFrame pdf = pd.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf = orca.DataFrame([[1, 2], [4, 5], [7, 8]], index=['cobra', 'viper', 'sidewinder'], columns=['max_speed', 'shield']) odf.loc[odf['shield'] > 5] = orca.DataFrame({'max_speed': 15, 'shield': 16}, index=['sidewinder']) pdf.loc[pdf['shield'] > 5] = pd.DataFrame({'max_speed': 15, 'shield': 16}, index=['sidewinder']) assert_frame_equal(odf.to_pandas(), pdf) odf.loc[['cobra', 'viper']] = orca.DataFrame({'max_speed': [15, 16], 'shield': [17, 18]}, index=['cobra', 'viper']) pdf.loc[['cobra', 'viper']] = pd.DataFrame({'max_speed': [15, 16], 'shield': [17, 18]}, index=['cobra', 'viper']) assert_frame_equal(odf.to_pandas(), pdf) odf.loc[[False, False, True]] = orca.DataFrame({'max_speed': 15, 'shield': 16}, index=['sidewinder']) pdf.loc[[False, False, True]] = pd.DataFrame({'max_speed': 15, 'shield': 16}, index=['sidewinder']) assert_frame_equal(odf.to_pandas(), pdf) odf.loc[odf['shield'] > 5] = orca.DataFrame({'max_speed': [15, 16], 'shield': [17, 18]}, index=['viper', 'sidewinder']) pdf.loc[pdf['shield'] > 5] = pd.DataFrame({'max_speed': [15, 16], 'shield': [17, 18]}, index=['viper', 'sidewinder']) assert_frame_equal(odf.to_pandas(), pdf) odf.loc[odf['shield'] > 6, ['max_speed']] = orca.DataFrame({'max_speed': 15, 'shield': 16}, index=['sidewinder']) pdf.loc[pdf['shield'] > 6, ['max_speed']] = pd.DataFrame({'max_speed': 15, 'shield': 16}, index=['sidewinder']) assert_frame_equal(odf.to_pandas(), pdf) odf.loc['cobra':'viper'] = orca.DataFrame({'max_speed': [15, 16], 'shield': [17, 18]}, index=['cobra', 'viper']) pdf.loc['cobra':'viper'] = pd.DataFrame({'max_speed': [15, 16], 'shield': [17, 18]}, index=['cobra', 'viper']) assert_frame_equal(odf.to_pandas(), pdf, check_dtype=False) pdf = pd.DataFrame([[1, 2, 1], [4, 5, 5], [7, 8, 7], [1, 5, 8], [7, 5, 1]], index=[7, 8, 9, 8, 9], columns=['max_speed', 'shield', 'size']) odf = orca.DataFrame([[1, 2, 1], [4, 5, 5], [7, 8, 7], [1, 5, 8], [7, 5, 1]], index=[7, 8, 9, 8, 9], columns=['max_speed', 'shield', 'size']) # TODO: orca不支持:当index有重复的列,通过一个dataframe去set # odf.loc[7:] = orca.DataFrame([[1, 1, 1], [5, 5, 5], [7, 7, 7], [8, 8, 8], [6, 6, 6]], index=[7, 8, 9, 8, 9], # columns=['max_speed', 'shield', 'size']) # pdf.loc[7:] = pd.DataFrame([[1, 1, 1], [5, 5, 5], [7, 7, 7], [8, 8, 8], [6, 6, 6]], index=[7, 8, 9, 8, 9], # columns=['max_speed', 'shield', 'size']) # assert_frame_equal(odf.to_pandas(), pdf) odf.loc[8] = orca.DataFrame([[1, 2, 1], [4, 5, 5]], index=[8, 8], columns=['max_speed', 'shield', 'size']) pdf.loc[8] = pd.DataFrame([[1, 2, 1], [4, 5, 5]], index=[8, 8], columns=['max_speed', 'shield', 'size'])