def test_dups_fancy_indexing(self): # GH 3455 from pandas.util.testing import makeCustomDataframe as mkdf df = mkdf(10, 3) df.columns = ['a', 'a', 'b'] cols = ['b', 'a'] result = df[['b', 'a']].columns expected = Index(['b', 'a', 'a']) self.assert_(result.equals(expected)) # across dtypes df = DataFrame([[1, 2, 1., 2., 3., 'foo', 'bar']], columns=list('aaaaaaa')) df.head() str(df) result = DataFrame([[1, 2, 1., 2., 3., 'foo', 'bar']]) result.columns = list('aaaaaaa') df_v = df.iloc[:, 4] res_v = result.iloc[:, 4] assert_frame_equal(df, result) # GH 3561, dups not in selected order ind = ['A', 'A', 'B', 'C'] df = DataFrame({'test': range(len(ind))}, index=ind) rows = ['C', 'B'] res = df.ix[rows] self.assert_(rows == list(res.index)) res = df.ix[Index(rows)] self.assert_(Index(rows).equals(res.index)) rows = ['C', 'B', 'E'] res = df.ix[rows] self.assert_(rows == list(res.index)) # inconcistent returns for unique/duplicate indices when values are missing df = DataFrame(randn(4, 3), index=list('ABCD')) expected = df.ix[['E']] dfnu = DataFrame(randn(5, 3), index=list('AABCD')) result = dfnu.ix[['E']] assert_frame_equal(result, expected)
def test_dups_fancy_indexing(self): # GH 3455 from pandas.util.testing import makeCustomDataframe as mkdf df = mkdf(10, 3) df.columns = ["a", "a", "b"] cols = ["b", "a"] result = df[["b", "a"]].columns expected = Index(["b", "a", "a"]) self.assert_(result.equals(expected)) # across dtypes df = DataFrame([[1, 2, 1.0, 2.0, 3.0, "foo", "bar"]], columns=list("aaaaaaa")) df.head() str(df) result = DataFrame([[1, 2, 1.0, 2.0, 3.0, "foo", "bar"]]) result.columns = list("aaaaaaa") df_v = df.iloc[:, 4] res_v = result.iloc[:, 4] assert_frame_equal(df, result) # GH 3561, dups not in selected order ind = ["A", "A", "B", "C"] df = DataFrame({"test": range(len(ind))}, index=ind) rows = ["C", "B"] res = df.ix[rows] self.assert_(rows == list(res.index)) res = df.ix[Index(rows)] self.assert_(Index(rows).equals(res.index)) rows = ["C", "B", "E"] res = df.ix[rows] self.assert_(rows == list(res.index)) # inconcistent returns for unique/duplicate indices when values are missing df = DataFrame(randn(4, 3), index=list("ABCD")) expected = df.ix[["E"]] dfnu = DataFrame(randn(5, 3), index=list("AABCD")) result = dfnu.ix[["E"]] assert_frame_equal(result, expected)
def test_dups_fancy_indexing(self): # GH 3455 from pandas.util.testing import makeCustomDataframe as mkdf df= mkdf(10, 3) df.columns = ['a','a','b'] cols = ['b','a'] result = df[['b','a']].columns expected = Index(['b','a','a']) self.assert_(result.equals(expected)) # across dtypes df = DataFrame([[1,2,1.,2.,3.,'foo','bar']], columns=list('aaaaaaa')) df.head() str(df) result = DataFrame([[1,2,1.,2.,3.,'foo','bar']]) result.columns = list('aaaaaaa') df_v = df.iloc[:,4] res_v = result.iloc[:,4] assert_frame_equal(df,result) # GH 3561, dups not in selected order ind = ['A', 'A', 'B', 'C'] df = DataFrame({'test':range(len(ind))}, index=ind) rows = ['C', 'B'] res = df.ix[rows] self.assert_(rows == list(res.index)) res = df.ix[Index(rows)] self.assert_(Index(rows).equals(res.index)) rows = ['C','B','E'] res = df.ix[rows] self.assert_(rows == list(res.index)) # inconcistent returns for unique/duplicate indices when values are missing df = DataFrame(randn(4,3),index=list('ABCD')) expected = df.ix[['E']] dfnu = DataFrame(randn(5,3),index=list('AABCD')) result = dfnu.ix[['E']] assert_frame_equal(result, expected)
def test_dups_fancy_indexing(self): # GH 3455 from pandas.util.testing import makeCustomDataframe as mkdf df= mkdf(10, 3) df.columns = ['a','a','b'] cols = ['b','a'] result = df[['b','a']].columns expected = Index(['b','a','a']) self.assert_(result.equals(expected)) # across dtypes df = DataFrame([[1,2,1.,2.,3.,'foo','bar']], columns=list('aaaaaaa')) df.head() str(df) result = DataFrame([[1,2,1.,2.,3.,'foo','bar']]) result.columns = list('aaaaaaa') df_v = df.iloc[:,4] res_v = result.iloc[:,4] assert_frame_equal(df,result)
def test_dups_fancy_indexing(self): # GH 3455 from pandas.util.testing import makeCustomDataframe as mkdf df = mkdf(10, 3) df.columns = ['a', 'a', 'b'] cols = ['b', 'a'] result = df[['b', 'a']].columns expected = Index(['b', 'a', 'a']) self.assert_(result.equals(expected)) # across dtypes df = DataFrame([[1, 2, 1., 2., 3., 'foo', 'bar']], columns=list('aaaaaaa')) df.head() str(df) result = DataFrame([[1, 2, 1., 2., 3., 'foo', 'bar']]) result.columns = list('aaaaaaa') df_v = df.iloc[:, 4] res_v = result.iloc[:, 4] assert_frame_equal(df, result)
def test_dups_fancy_indexing(self): # GH 3455 from pandas.util.testing import makeCustomDataframe as mkdf df= mkdf(10, 3) df.columns = ['a','a','b'] cols = ['b','a'] result = df[['b','a']].columns expected = Index(['b','a','a']) self.assert_(result.equals(expected)) # across dtypes df = DataFrame([[1,2,1.,2.,3.,'foo','bar']], columns=list('aaaaaaa')) df.head() str(df) result = DataFrame([[1,2,1.,2.,3.,'foo','bar']]) result.columns = list('aaaaaaa') df_v = df.iloc[:,4] res_v = result.iloc[:,4] assert_frame_equal(df,result) # GH 3561, dups not in selected order df = DataFrame({'test': [5,7,9,11]}, index=['A', 'A', 'B', 'C']) rows = ['C', 'B'] expected = DataFrame({'test' : [11,9]},index=rows) result = df.ix[rows] assert_frame_equal(result, expected) result = df.ix[Index(rows)] assert_frame_equal(result, expected) rows = ['C','B','E'] expected = DataFrame({'test' : [11,9,np.nan]},index=rows) result = df.ix[rows] assert_frame_equal(result, expected) # inconsistent returns for unique/duplicate indices when values are missing df = DataFrame(randn(4,3),index=list('ABCD')) expected = df.ix[['E']] dfnu = DataFrame(randn(5,3),index=list('AABCD')) result = dfnu.ix[['E']] assert_frame_equal(result, expected) # GH 4619; duplicate indexer with missing label df = DataFrame({"A": [0, 1, 2]}) result = df.ix[[0,8,0]] expected = DataFrame({"A": [0, np.nan, 0]},index=[0,8,0]) assert_frame_equal(result,expected) df = DataFrame({"A": list('abc')}) result = df.ix[[0,8,0]] expected = DataFrame({"A": ['a', np.nan, 'a']},index=[0,8,0]) assert_frame_equal(result,expected) # non unique with non unique selector df = DataFrame({'test': [5,7,9,11]}, index=['A','A','B','C']) expected = DataFrame({'test' : [5,7,5,7,np.nan]},index=['A','A','A','A','E']) result = df.ix[['A','A','E']] assert_frame_equal(result, expected)