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

Adding Arthimetic operations #4

Merged
merged 2 commits into from
Jan 11, 2016
Merged

Conversation

mortonjt
Copy link

@mortonjt mortonjt commented Jan 7, 2016

Let me know if I'm missing anything.

Note, I didn't think it would make sense to have reverse operations (i.e. 1+Interval(1, 2))
So that functionality isn't added atm.

raise TypeError("unsupported operand type(s) for +: '%s' and '%s'" %
(type(self).__name__, type(y).__name__))
else:
raise TypeError("unsupported operand type(s) for +: '%s' and '%s'" %
Copy link
Owner

Choose a reason for hiding this comment

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

you can simply return NotImplemented to get Python to raise this default error

Copy link
Owner

Choose a reason for hiding this comment

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

@shoyer
Copy link
Owner

shoyer commented Jan 7, 2016

I do think it probably makes sense to define the reverse operators, at least for + for * -- these are generally commutative operators. For / and -, the result will almost always be an invalid interval, so it's OK to skip them.

@mortonjt
Copy link
Author

mortonjt commented Jan 7, 2016

Just realized that multiplication and division is broken - will fix in a bit ...

@mortonjt
Copy link
Author

mortonjt commented Jan 8, 2016

Note that this seems to only work for PY3. Not sure what's going on with PY2 ...

@mortonjt
Copy link
Author

mortonjt commented Jan 9, 2016

That should cover it. @shoyer, do you think the tests for PY2 and PY3 can be specified in the travis test?

Otherwise, I think this should be good to go.

self.assertEqual(expected, actual)

expected = Interval(-1, 0)
actual = 1 - self.interval
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is right -- [0, 1) - 1 should be [-1, 0), but 1 - [0, 1) should be [1, 0), which is not a valid interval.

Copy link
Author

Choose a reason for hiding this comment

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

Ok. I'll get rid of that test case, as suggested in the comment below.

@shoyer
Copy link
Owner

shoyer commented Jan 9, 2016

Travis already tests both python 2 and python 3

On Sat, Jan 9, 2016 at 11:47 AM, mortonjt notifications@github.com wrote:

That should cover it. @shoyer https://github.com/shoyer, do you think
the tests for PY2 and PY3 can be specified in the travis test?

Otherwise, I think this should be good to go.


Reply to this email directly or view it on GitHub
#4 (comment).

STY: Adding @shoyer's comments

BUG: Fixing multiplication and division

ENH: Adding in PY2 compatible division

TST: Adding PY2 specific test.  May want to configure in travis ...

TST: Modifying division test to handle both PY2 and PY3
@mortonjt
Copy link
Author

Modified the division test case to handle both PY2 and PY3. Let me know if I'm missing anything

shoyer added a commit that referenced this pull request Jan 11, 2016
Adding Arthimetic operations
@shoyer shoyer merged commit 8c0ce10 into shoyer:IntervalIndex Jan 11, 2016
@shoyer
Copy link
Owner

shoyer commented Jan 11, 2016

looks great -- thanks!

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.

2 participants