Skip to content

ENH: add mm->qm divmod - #12683

Merged
mattip merged 2 commits into
numpy:masterfrom
tylerjereddy:timedelta64_divmod
Jan 21, 2019
Merged

mattip merged 2 commits into
numpy:masterfrom
tylerjereddy:timedelta64_divmod

Conversation

@tylerjereddy

@tylerjereddy tylerjereddy commented Jan 7, 2019 •

Copy link
Copy Markdown
Contributor

This still needs work -- something isn't quite right according to the unit tests.

Would be nice if an inner loop that performs the operations of two other inner loops could just gracefully call the those other two inner loops, but I think Eric & I have had that discussion before & there are issues with i.e., nesting binop loops.

Comment thread numpy/core/src/umath/loops.c.src Resolved
Comment thread numpy/core/src/umath/loops.c.src Resolved
Comment thread numpy/core/src/umath/loops.c.src Resolved
Comment thread numpy/core/tests/test_datetime.py Resolved
@tylerjereddy

Copy link
Copy Markdown
Contributor Author

Revised based on feedback so far -- if m8 remainder operation really needs a fix I suppose we could apply that here as well rather than having divmod behave differently.

@eric-wieser

eric-wieser commented Jan 8, 2019 •

Copy link
Copy Markdown
Member

We might want to consult the mailing list on whether we should revise the behavior of timedelta64(1) % timedelta64(0) to be more inline with np.float64(1) / np.float64(0). Whatever we decide, obviously divmod should match.

Otherwise looks good to me.

@eric-wieser

Copy link
Copy Markdown
Member

Ah, I'd forgotten how recently we added modulo support (#12120), so we can probably get away with fixing it, especially if we backport. Was there any discussion about what %0 should return there?

@miccoli

miccoli commented Jan 8, 2019

Copy link
Copy Markdown
Contributor

@eric-wieser : I do not remember that in #12120 the %0 case was discussed: I would suggest to consider the current behaviour (1 % 0 == 0) a bug.

There are still some open points in the np.timedelta64 implementation which were discussed in #12120:

  1. np.timedelta64(13) / 7 vs np.timedelta64(13) // 7
  2. np.timedelta64(13) / np.timedelta(7) vs np.timedelta64(13) // np.timedelta(7)

IMHO currently (1.16.0rc2) we have

  • correct:

    • np.timedelta64(13) // 7 == np.timedelta64(1)
    • np.timedelta64(13) / np.timedelta64(7) == 1.857_142_857_142_857_2
  • wrong:

    • np.timedelta64(13) / 7 == np.timedelta64(1)
      which instead should be
      np.timedelta64(2) or
      np.timedelta64(1_857, 'ms') or
      np.timedelta64(1_857_143, 'us') or
      numpy.timedelta64(1_857_142_857,'ns') depending on how (or whether) dividend and divisor are promoted before division
  • not implemented:

    • np.timedelta64(13) // np.timedelta64(7)
      which should be 1 according to the invariant
      a == (a // b)*b + a%b

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

@miccoli

  • floordiv with two timedelta64 operands should be available in master now
  • I didn't touch the cases involving timedelta64 with integer operands recently, so those have probably been that way for a while -- not sure how disruptive those behavior changes would be to make now / try to backport
  • looks like both you / mailing list agree that the modulus % 0 case for two timedelta64 operands is a bug, and should return NaT; I'll probably aim to have one commit that fixes that bug in remainder (to facilitate possible backport), and then a second commit to add divmod with the revised remainder behavior baked in

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

Revised the PR with separate commits for the remainder bug fix and the feature addition / typecast cleanup, so that the former may be backported if desired.

@eric-wieser

Copy link
Copy Markdown
Member

I'd probably be in favor of just backporting everything

Comment thread numpy/core/tests/test_datetime.py Resolved
@eric-wieser eric-wieser added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Jan 10, 2019

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, but needs a release note. Since this is a simple extension, and divmod is something I'd expect to exist alongside %, I think we should all of this in 1.16, not just the bug fix.

Needs a release note in either 1.16 or 1.17, depending on what we decide.

@tylerjereddy tylerjereddy changed the title WIP, ENH: add mm->qm divmod ENH: add mm->qm divmod Jan 10, 2019
@tylerjereddy

Copy link
Copy Markdown
Contributor Author

Refined the test as requested & removed WIP tag.

I'll hold off on the release note until we have a decision on the milestone target.

@seberg

seberg commented Jan 11, 2019

Copy link
Copy Markdown
Member

Considering how super new it is, I guess it is fine to put the NaN fix definitely into 1.16 (even 1.16.1, don't want to make things weird with already rc's out for long). Backporting the new functionality seems OK to me as well, since even if there is something wrong, I don't think it can possibly cause a regression. If this wasn't the LTS I would probably be against it.

So I would say: lets just target 1.16.1.

@charris

charris commented Jan 11, 2019

Copy link
Copy Markdown
Member

If we want it in 1.16, should try rebasing on that branch with a release note, then forward port without the release note. The 1.16 release notes will be forward ported after release. I would like to make the 1.16 release this weekend.

@tylerjereddy tylerjereddy added this to the 1.16.1 release milestone Jan 12, 2019
@tylerjereddy

Copy link
Copy Markdown
Contributor Author

I'll tentatively add the 1.16.1 milestone & try the rebase thing locally first, etc. I've been stuck working on the SciPy paper revisions / organization for most of today.

@eric-wieser

Copy link
Copy Markdown
Member

Rebasing on f07a38d will make both the forward and backport easy

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Jan 16, 2019
@charris

charris commented Jan 18, 2019

Copy link
Copy Markdown
Member

Needs a release note. Put it in the 1.17.0-notes and I'll copy it to the 1.16.1-notes. @eric-wieser backports are really easy anyway unless there are a ton of commits with conflicts. I'll be interested to see if Tyler can still add the release note without problems.

* modulus operation with two timedelta64
operands now returns NaT in the case of
division by zero, rather than returning
zero
* add timedelta64 divmod inner
loop with type signature mm->qm

* also adjusted typecasting in
mm_q floor division to match the
approach used here (should not
change any behavior)
@tylerjereddy

tylerjereddy commented Jan 18, 2019 •

Copy link
Copy Markdown
Contributor Author

Ok, added a release note (via an amend), rebased on latest master, and force pushed. This will obviously increase the likelihood of master branch merge conflict eventually.

assert_equal(divmod(op1, op2), expected)

@pytest.mark.parametrize("op1, op2", [
# reuse cases from floordiv

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you reuse them in the source by creating a global variable with these cases?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

or a class (same thing, just makes the global state local to the class)

divmod operation is now supported for two ``timedelta64`` operands
------------------------------------------------------------------
The divmod operator now handles two ``np.timedelta64`` operands, with
type signature mm->qm.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: double backquotes mm->qm

@mattip

mattip commented Jan 20, 2019

Copy link
Copy Markdown
Member

two small nits, but not critical. Will merge later today

@mattip
mattip merged commit 3cbc11a into numpy:master Jan 21, 2019
@mattip

mattip commented Jan 21, 2019

Copy link
Copy Markdown
Member

Thanks Tyler

@charris charris mentioned this pull request Jan 21, 2019
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jan 21, 2019
@charris charris removed this from the 1.16.1 release milestone Jan 21, 2019
@charris charris removed the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Jan 21, 2019
@charris

charris commented Jan 21, 2019

Copy link
Copy Markdown
Member

I've made the additions to the 1.16.1 release notes.

@tylerjereddy
tylerjereddy deleted the timedelta64_divmod branch January 22, 2019 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants