Skip to content

Commit

Permalink
data frame equality test with ignore_row_order=TRUE detects differenc…
Browse files Browse the repository at this point in the history
…e in number of rows. closes tidyverse#1065
  • Loading branch information
romainfrancois committed Apr 20, 2015
1 parent eb87057 commit 887a455
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
* Fixed issue about complex variables used in `summarise` (#933).

* Set operations give more useful error message on incompatible data frames (#903).


* `all.equal` gives the correct result when `ignore_row_order` is `TRUE` (#1065).

# dplyr 0.4.1

* Don't assume that RPostgreSQL is available.
Expand Down
9 changes: 5 additions & 4 deletions src/dplyr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,9 +1413,12 @@ dplyr::BoolResult equal_data_frame(DataFrame x, DataFrame y, bool ignore_col_ord

// train the map in both x and y
int nrows_x = x.nrows() ;
for( int i=0; i<nrows_x; i++) map[i].push_back(i) ;

int nrows_y = y.nrows() ;

if( nrows_x != nrows_y )
return no_because( "Different number of rows" ) ;

for( int i=0; i<nrows_x; i++) map[i].push_back(i) ;
for( int i=0; i<nrows_y; i++) map[-i-1].push_back(-i-1) ;

RowTrack track_x( "Rows in x but not y: " ) ;
Expand Down Expand Up @@ -1457,8 +1460,6 @@ dplyr::BoolResult equal_data_frame(DataFrame x, DataFrame y, bool ignore_col_ord
if(ok && ignore_row_order) return yes();

if( !ignore_row_order ){
if( nrows_x != nrows_y )
return no_because( "Different number of rows" ) ;
for( int i=0; i<nrows_x; i++){
if( !visitors.equal( i, -i-1) ){
return no_because( "Same row values, but different order" ) ;
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-equality.r
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ test_that("all.equal.data.frame handles data.frames with NULL names", {
names(x) <- NULL
expect_true(all.equal(x,x))
})

test_that( "data frame equality test with ignore_row_order=TRUE detects difference in number of rows. #1065", {
DF1 <- data_frame(a = 1:4, b = letters[1:4])
DF2 <- data_frame(a = c(1:4,4L), b = letters[c(1:4,4L)])
expect_false( isTRUE(all.equal(DF1, DF2, ignore_row_order=TRUE)))
})

0 comments on commit 887a455

Please sign in to comment.