From f7a4e17c69357166dd824f06c769534773b5c489 Mon Sep 17 00:00:00 2001 From: ARSH SHARMA <184517@nith.ac.in> Date: Fri, 21 Aug 2020 12:38:24 +0530 Subject: [PATCH 01/10] Update News.md --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index ead8651853..f0679a7eae 100644 --- a/NEWS.md +++ b/NEWS.md @@ -38,7 +38,8 @@ * add `rownumber` to `DataFrameRow` ([#2356](https://github.com/JuliaData/DataFrames.jl/pull/2356)) * allow passing column name to specify the position where a new columns should be inserted in `insertcols!` ([#2365](https://github.com/JuliaData/DataFrames.jl/pull/2365)) - +* add `isapprox` method to check for approximate equality between two dataframes + ([#2373](https://github.com/JuliaData/DataFrames.jl/pull/2373)) ## Deprecated * `DataFrame!` is now deprecated ([#2338](https://github.com/JuliaData/DataFrames.jl/pull/2338)) From 4c6b0616a8ccc631cecef5170a2c1c7f533fffb6 Mon Sep 17 00:00:00 2001 From: ARSH SHARMA <184517@nith.ac.in> Date: Fri, 21 Aug 2020 22:37:36 +0530 Subject: [PATCH 02/10] Nit's --- src/DataFrames.jl | 1 + src/abstractdataframe/abstractdataframe.jl | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/DataFrames.jl b/src/DataFrames.jl index 709deb943e..a8e5bf9b60 100644 --- a/src/DataFrames.jl +++ b/src/DataFrames.jl @@ -5,6 +5,7 @@ using Reexport, SortingAlgorithms, Compat, Unicode, PooledArrays @reexport using CategoricalArrays, Missings, InvertedIndices using Base.Sort, Base.Order, Base.Iterators using TableTraits, IteratorInterfaceExtensions +import LinearAlgebra: norm import DataAPI, DataAPI.All, diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index 5653c4ceba..894b62ba8d 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -410,6 +410,13 @@ function Base.isequal(df1::AbstractDataFrame, df2::AbstractDataFrame) return true end +function Base.isapprox(df1::AbstractDataFrame, df2::AbstractDataFrame; + atol::Real=0, rtol::Real=atol>0 ? 0 : √eps(), + nans::Bool=false, norm::Function=norm) + size(df1) == size(df2) || throw(DimensionMismatch("dimensions must match: a has dims $(size(df1)), b has dims $(size(df2))")) + isequal(index(df1), index(df2)) || throw(ArgumentError("column names of passed data frames do not match")) + return all(isapprox.(eachcol(df1), eachcol(df2), atol=atol, rtol=rtol, nans=nans, norm=norm)) +end ############################################################################## ## ## Description From be183f9526f8f991c1096a619193a77ef0793b5b Mon Sep 17 00:00:00 2001 From: ARSH SHARMA <184517@nith.ac.in> Date: Sat, 22 Aug 2020 00:32:41 +0530 Subject: [PATCH 03/10] Add docstring --- src/abstractdataframe/abstractdataframe.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index 894b62ba8d..b8d56ab01c 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -409,7 +409,10 @@ function Base.isequal(df1::AbstractDataFrame, df2::AbstractDataFrame) end return true end - +""" +Tests for approximate equality between two DataFrames + `isapprox(::AbstractDataFrame,::AbstractDataFrame; kwargs...)` +""" function Base.isapprox(df1::AbstractDataFrame, df2::AbstractDataFrame; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps(), nans::Bool=false, norm::Function=norm) From 2f01176ba7cf93346b6e99689942d9e7fa69082d Mon Sep 17 00:00:00 2001 From: Arsh Sharma <43717431+Sov-trotter@users.noreply.github.com> Date: Sat, 22 Aug 2020 00:56:20 +0530 Subject: [PATCH 04/10] Refactor docstring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bogumił Kamiński --- src/abstractdataframe/abstractdataframe.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index b8d56ab01c..448af2474c 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -410,8 +410,12 @@ function Base.isequal(df1::AbstractDataFrame, df2::AbstractDataFrame) return true end """ -Tests for approximate equality between two DataFrames - `isapprox(::AbstractDataFrame,::AbstractDataFrame; kwargs...)` + isapprox(df1::AbstractDataFrame, df2::AbstractDataFrame; + rtol::Real=atol>0 ? 0 : √eps, atol::Real=0, nans::Bool=false, norm::Function) + +Inexact equality comparison. `df1` and `df2` must have the same size and column names. +Return `true` if `isapprox` with given `rtol`, `atol`, `nans`, and `norm` keyword arguments +applied to all pairs of columns stored in `df1` and `df2` returns `true`. """ function Base.isapprox(df1::AbstractDataFrame, df2::AbstractDataFrame; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps(), From 15f19f6da366e46524fa2605df83ea0c20312e54 Mon Sep 17 00:00:00 2001 From: ARSH SHARMA <184517@nith.ac.in> Date: Sat, 22 Aug 2020 01:24:19 +0530 Subject: [PATCH 05/10] Minor nit --- src/abstractdataframe/abstractdataframe.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index 448af2474c..fc23d43e9f 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -409,6 +409,7 @@ function Base.isequal(df1::AbstractDataFrame, df2::AbstractDataFrame) end return true end + """ isapprox(df1::AbstractDataFrame, df2::AbstractDataFrame; rtol::Real=atol>0 ? 0 : √eps, atol::Real=0, nans::Bool=false, norm::Function) From 1161e02fd653c800c86d2d16819ae0015b179410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 23 Aug 2020 00:19:09 +0200 Subject: [PATCH 06/10] Apply suggestions from code review Co-authored-by: Milan Bouchet-Valat --- src/abstractdataframe/abstractdataframe.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index fc23d43e9f..66d47ac317 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -412,10 +412,11 @@ end """ isapprox(df1::AbstractDataFrame, df2::AbstractDataFrame; - rtol::Real=atol>0 ? 0 : √eps, atol::Real=0, nans::Bool=false, norm::Function) + rtol::Real=atol>0 ? 0 : √eps, atol::Real=0, + nans::Bool=false, norm::Function=norm) Inexact equality comparison. `df1` and `df2` must have the same size and column names. -Return `true` if `isapprox` with given `rtol`, `atol`, `nans`, and `norm` keyword arguments +Return `true` if `isapprox` with given keyword arguments applied to all pairs of columns stored in `df1` and `df2` returns `true`. """ function Base.isapprox(df1::AbstractDataFrame, df2::AbstractDataFrame; From e055ba34461660229506f7c87cbbb4fcda53a16e Mon Sep 17 00:00:00 2001 From: ARSH SHARMA <184517@nith.ac.in> Date: Sun, 23 Aug 2020 12:12:05 +0530 Subject: [PATCH 07/10] Add linearalgebra dep --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index c9534d9fc6..d3bee6ff1e 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" Future = "9fa8497b-333b-5362-9e8d-4d0656e87820" InvertedIndices = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" From 725c194795baa5b9d045083eb302213f1dfd5445 Mon Sep 17 00:00:00 2001 From: ARSH SHARMA <184517@nith.ac.in> Date: Sun, 23 Aug 2020 13:41:34 +0530 Subject: [PATCH 08/10] Add isapprox to equality section in functions Add isapprox to equality section in functions Add isapprox to equality section in functions --- docs/src/lib/functions.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/src/lib/functions.md b/docs/src/lib/functions.md index 0356492da8..8c62e7ff73 100644 --- a/docs/src/lib/functions.md +++ b/docs/src/lib/functions.md @@ -124,3 +124,8 @@ eachrow values pairs ``` + +## Equality +```@docs +isapprox +``` From d2f1079aa3efa9cac21bcc364dbe3d138b19e07f Mon Sep 17 00:00:00 2001 From: ARSH SHARMA <184517@nith.ac.in> Date: Sun, 23 Aug 2020 14:50:17 +0530 Subject: [PATCH 09/10] test isapprox --- test/constructors.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/constructors.jl b/test/constructors.jl index 6bd54d74a5..38d5e08dda 100644 --- a/test/constructors.jl +++ b/test/constructors.jl @@ -223,6 +223,8 @@ end @test size(df, 1) == 3 @test size(df, 2) == 2 @test isequal(df, DataFrame(x1 = [0.0, 0.0, 0.0], x2 = [1.0, 1.0, 1.0])) + @test isapprox(df, DataFrame(x1 = [0.0, 0.0, 0.0], x2 = [1.0, 1.0, 1.0])) + @test isapprox(df, DataFrame(x1 = [0.0, 0.0, 0.0], x2 = [1.000000010000, 1.0, 1.0])) df = DataFrame(:type => [], :begin => []) @test propertynames(df) == [:type, :begin] From 98fc5579ca2ebe45947b0a72c887698545b73485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 23 Aug 2020 15:56:34 +0200 Subject: [PATCH 10/10] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index f0679a7eae..7e0c341a90 100644 --- a/NEWS.md +++ b/NEWS.md @@ -40,6 +40,7 @@ inserted in `insertcols!` ([#2365](https://github.com/JuliaData/DataFrames.jl/pull/2365)) * add `isapprox` method to check for approximate equality between two dataframes ([#2373](https://github.com/JuliaData/DataFrames.jl/pull/2373)) + ## Deprecated * `DataFrame!` is now deprecated ([#2338](https://github.com/JuliaData/DataFrames.jl/pull/2338))