xnd-project / libxnd

Subsumed into xnd
https://xnd.io/
BSD 3-Clause "New" or "Revised" License
80 stars 12 forks source link

[WIP] Structural equality tests. #45

Open pearu opened 5 years ago

pearu commented 5 years ago

This PR introduces identity function for structural equality tests.

skrah commented 5 years ago

There is a problem with non-contiguous buffer imports, where the actual start of the buffer cannot be known:

>>> a = np.arange(10000000)[::-1]
>>> x = xnd.from_buffer(a)
>>> y = xnd.from_buffer(a)
>>> x.strict_equal(y)
True
>>> x.identical(y)
Segmentation fault (core dumped)

I think we may have to abandon the idea of complete buffer equality (which is less interesting anyway) and do a version of strict equal that compares NaN and NA as equal.

skrah commented 5 years ago

FWIW, R's identical also compares the results of slicing and not the whole data structure:

> df1 <- data.frame(a = c(1, 2, 3, 4), b = c(1, 2, 3, 4))
> df2 <- data.frame(a = c(1, 2), b = c(1, 2))
> df1 %>% slice(1)
  a b
1 1 1
> df2 %>% slice(1)
  a b
1 1 1
> identical(df1, df2)
[1] FALSE
> identical(df1 %>% slice(1), df2 %>% slice(1))
[1] TRUE