From 1f995bc6b0b813f8fa0281b83b0524943d1c146f Mon Sep 17 00:00:00 2001 From: Jonathan Malmaud Date: Fri, 22 Jul 2022 19:49:31 -0700 Subject: [PATCH 1/2] Equality tests won't throw errors. Fixes #95. --- src/Pandas.jl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Pandas.jl b/src/Pandas.jl index 8b244ec..57820b9 100644 --- a/src/Pandas.jl +++ b/src/Pandas.jl @@ -376,7 +376,6 @@ end for (jl_op, py_op, py_opᵒ) in [(:+, :__add__, :__add__), (:*, :__mul__, :__mul__), (:/, :__div__, :__rdiv__), (:-, :__sub__, :__rsub__), - (:(==), :__eq__, :__eq__), (:!=, :__ne__, :__ne__), (:>, :__gt__, :__lt__), (:<, :__lt__, :__gt__), (:>=, :__ge__, :__le__), (:<=, :__le__, :__ge__), (:&, :__and__, :__and__), (:|, :__or__, :__or__)] @@ -397,6 +396,19 @@ for (jl_op, py_op, py_opᵒ) in [(:+, :__add__, :__add__), (:*, :__mul__, :__mul end end +# Special-case the handling of equality-testing to always consider PandasWrapped +# objects as unequal to non-wrapped objects. +(==)(x::PandasWrapped, y) = false +(==)(x, y::PandasWrapped) = false +(!=)(x::PandasWrapped, y) = true +(!=)(x, y::PandasWrapped) = true +function (==)(x::PandasWrapped, y::PandasWrapped) + pandas_wrap(x.pyo.__eq__(y)) +end +function (!=)(x::PandasWrapped, y::PandasWrapped) + pandas_wrap(x.pyo.__neq__(y)) +end + for op in [(:-, :__neg__)] @eval begin $(op[1])(x::PandasWrapped) = pandas_wrap(x.pyo.$(quot(op[2]))()) From b8a1a8a232837a7886bc554b3a7265520745cc68 Mon Sep 17 00:00:00 2001 From: Jonathan Malmaud Date: Mon, 25 Jul 2022 10:09:48 -0700 Subject: [PATCH 2/2] Update tests --- test/runtests.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index af39b2d..93642a0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -73,3 +73,11 @@ julia_df = DataFrames.DataFrame(py_df) julia_df= DataFrames.DataFrame(C = 1:4, A = 5:8, B = 9:12) py_df = Pandas.DataFrame(julia_df) @test all(Pandas.columns(py_df) .== ["C","A","B"]) + +df1 = Pandas.Series(1:2) +df2 = Pandas.Series(1:2) +df3 = Pandas.Series(3:4) + +@test all(df1 == df1) +@test all(df1 == df2) +@test df1 != [1, 2]