Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basefix #67

Merged
merged 8 commits into from
Jun 2, 2014
Merged

Basefix #67

merged 8 commits into from
Jun 2, 2014

Conversation

squirrelo
Copy link
Contributor

Now check types are the same for base class as objects that were of different type but same ID were considered equal.

Also adds skeleton for data object so tests don't fail.

@@ -80,7 +80,7 @@ def __init__(self, id_):
self._id = id_

def __eq__(self, other):
return other._id == self._id
return other._id == self._id and type(self) == type(other)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't _id equality imply they're the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, accidentally compared a RawData object and PreprocessedData object with the same id and they were considered equal. Need the type check. It's because this is in the base class I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since _id isn't globally unique then, how confident are you that create and delete work as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by that? Create and delete are defined by each child object, so they should work regardless of this issue. This is more for comparison after creation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like, right now, you can delete something of type foo using an instance of type bar. is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that, you pass an ID of the thing you want to delete as a class method. You can't delete foo with bar thing because of this. All you are using is the integer id.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change delete to be instance method instead of a class method? This will solve this issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way, de delete functions won't need to get an id, they will get them from the instance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems reasonable, is there a need to pass an _id to delete?

On Mon, Jun 2, 2014 at 12:06 PM, josenavas notifications@github.com wrote:

In qiita_db/base.py:

@@ -80,7 +80,7 @@ def init(self, id_):
self.id = id

 def __eq__(self, other):
  •    return other._id == self._id
    
  •    return other._id == self._id and type(self) == type(other)
    

This way, de delete functions won't need to get an id, they will get them
from the instance.


Reply to this email directly or view it on GitHub
https://github.com/biocore/qiita/pull/67/files#r13298288.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it was a class method it needed an id. I won't be needed once it is an
instance method.

2014-06-02 12:13 GMT-06:00 Daniel McDonald notifications@github.com:

In qiita_db/base.py:

@@ -80,7 +80,7 @@ def init(self, id_):
self.id = id

 def __eq__(self, other):
  •    return other._id == self._id
    
  •    return other._id == self._id and type(self) == type(other)
    

that seems reasonable, is there a need to pass an _id to delete?
… <#1465dc9952698c34_>
On Mon, Jun 2, 2014 at 12:06 PM, josenavas notifications@github.com
wrote: In qiita_db/base.py: > @@ -80,7 +80,7 @@ def init(self, id_): >
self.id = id > > def eq(self, other): > - return other._id ==
self._id > + return other._id == self._id and type(self) == type(other)
This way, de delete functions won't need to get an id, they will get them
from the instance. — Reply to this email directly or view it on GitHub <
https://github.com/biocore/qiita/pull/67/files#r13298288>.


Reply to this email directly or view it on GitHub
https://github.com/biocore/qiita/pull/67/files#r13298667.

Jose Navas

@josenavas
Copy link
Contributor

👍 Good catch on the __eq__ stuff. Since all our classes are based on this class, the check for type is needed. Thanks @squirrelo

@wasade if you don't see any further issues, feel free to merge it

@@ -80,7 +80,7 @@ def __init__(self, id_):
self._id = id_

def __eq__(self, other):
return other._id == self._id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion here is that we separate checks one per if statement. This is very helpful for debugging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this point... it will return true or false anyways, you're not going to know in which if statement it was providing the output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but if you add a print statement inside the if conditional then you
can quickly check that as opposed to having to break the contitional at
the botton in mutliple lines.

On (Jun-02-14|10:37), josenavas wrote:

@@ -80,7 +80,7 @@ def init(self, id_):
self.id = id

 def __eq__(self, other):
  •    return other._id == self._id
    

I don't see this point... it will return true or false anyways, you're not going to know in which if statement it was providing the output.


Reply to this email directly or view it on GitHub:
https://github.com/biocore/qiita/pull/67/files#r13296674

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adds clarity in the traceback as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, broken up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

On (Jun-02-14|11:10), Joshua Shorenstein wrote:

@@ -80,7 +80,7 @@ def init(self, id_):
self.id = id

 def __eq__(self, other):
  •    return other._id == self._id
    

OK, broken up.


Reply to this email directly or view it on GitHub:
https://github.com/biocore/qiita/pull/67/files#r13298524

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.61%) when pulling e3db027 on squirrelo:basefix into e448c10 on biocore:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.32%) when pulling d8d8757 on squirrelo:basefix into e448c10 on biocore:master.

@@ -80,7 +80,10 @@ def __init__(self, id_):
self._id = id_

def __eq__(self, other):
return other._id == self._id
if other._id == self._id:
if type(self) == type(other):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say that it makes sense to broke things up on the other order, first by type and then by id. What if you pass an integer instead of a subclass? Currently it will raise an error, while if you change the order it will just return false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, like this:

if other._id != self._id:
    return False
if type(self) != type(other):
    return False
return True

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will still fail, it should be this way:

if type(self) != type(other):
    return False
if other._id != self._id:
    return False
return True

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes.

On (Jun-02-14|11:35), josenavas wrote:

@@ -80,7 +80,10 @@ def init(self, id_):
self.id = id

 def __eq__(self, other):
  •    return other._id == self._id
    
  •    if other._id == self._id:
    
  •        if type(self) == type(other):
    

It will still fail, it should be this way:

if type(self) != type(other):
    return False
if other._id != self._id:
    return False
return True

Reply to this email directly or view it on GitHub:
https://github.com/biocore/qiita/pull/67/files#r13299908

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, ok. Fixed.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.32%) when pulling 582031a on squirrelo:basefix into e448c10 on biocore:master.

@josenavas
Copy link
Contributor

I know you haven't change it, but can you remove the @classmethod decorator from the delete function, as well as the cls parameters. Thanks.

@squirrelo
Copy link
Contributor Author

Nevermind. Done.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.44%) when pulling 8901c3c on squirrelo:basefix into e448c10 on biocore:master.

@@ -80,7 +79,11 @@ def __init__(self, id_):
self._id = id_

def __eq__(self, other):
return other._id == self._id
if other._id != self._id:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order here is still wrong, check my previous comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID is faster to check though, so probably faster this way. If the ID is different, it doesn't matter if it's the same type or not; it's considered not equal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faster, but it will raise an error instead of returning false if "other" is not a subclass of BaseClass. Please check all the comments that we make in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, right. Didn't catch that was why the error was raised during the convo.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.44%) when pulling a2c5104 on squirrelo:basefix into e448c10 on biocore:master.

@josenavas
Copy link
Contributor

It looks good to me now.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.44%) when pulling ac9863c on squirrelo:basefix into e448c10 on biocore:master.

@squirrelo
Copy link
Contributor Author

I think this is good now.

@josenavas
Copy link
Contributor

@wasade @ElDeveloper if it looks good to you, feel free to merge it.

wasade added a commit that referenced this pull request Jun 2, 2014
@wasade wasade merged commit 223b7f0 into qiita-spots:master Jun 2, 2014
@squirrelo squirrelo deleted the basefix branch June 4, 2014 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants