Git Product home page Git Product logo

Comments (5)

daiyip avatar daiyip commented on May 5, 2024

Good question. It might seems confusing to return the same object itself, the mental model was to simulate a diff tool, which has the left side and the right side - when both sides are the same, they appear to be the same content, which is the object itself.

I think a better treatment is that when pg.diff(A(x='1'), A(x='1')) (mode='diff'), it should return None, and when the mode='same' or 'both', it returns the object itself. Does this make sense? I will be sending out a PR for this.

from pyglove.

D-X-Y avatar D-X-Y commented on May 5, 2024

I would prefer to be consistent with non-identical case.
For example, it make sense to me to see A(IDENTICAL) instead of None because the later case need additional handling on None. Also, if we have a simple api to just get a bool value for whether two objects are the same or not along with this diff, that would also be helpful (I guess we already have one?) :)

from pyglove.

daiyip avatar daiyip commented on May 5, 2024

It took me some revisit to realize that current behavior is actually correct.

The pg.diff(A(x='1', A(x='1')) returns pg.Diff(A(x='1'), A(x='1')) ('D' is capitalized) instead of A(x='1'), though str(pg.Diff) uses the str form of the value if left and right are identical. You can simply apply a bool operator on pg.Diff (e.g. bool(pg.Diff(...)) or use predicate like if not pg.diff(...).

from pyglove.

daiyip avatar daiyip commented on May 5, 2024

Okay, I tuned the behavior a little bit - now pg.diff(A(x='1'), A(x='1')) (mode='diff' by default) will return pg.Diff(left=pg.Diff.MISSING, right=pg.Diff.MISSING) whose representation or string is 'No diff'. For pg.diff(A(x='1', A(x='1'), mode='same'), it will return pg.Diff(left=A(x='1'), right=A(x='1')), which will print as A(x='1').

Please see Commit# e31fa99 for details.

from pyglove.

D-X-Y avatar D-X-Y commented on May 5, 2024

This makes a lot of sense to me, thanks for your quick fix!

from pyglove.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.