Skip to content

BUG: timedelta64 now accepts NumPy ints - #11852

Merged
shoyer merged 1 commit into
numpy:masterfrom
tylerjereddy:issue_7617
Oct 19, 2018
Merged

shoyer merged 1 commit into
numpy:masterfrom
tylerjereddy:issue_7617

Conversation

@tylerjereddy

Copy link
Copy Markdown
Contributor

Fixes #7617

I should (probably) add more tests & maybe account for the duplication logic (another branch of the C function adjusted here uses that block too) by abstracting to a "helper" function.

@charris

charris commented Sep 1, 2018

Copy link
Copy Markdown
Member

Testing failure Looks like travis messing up. Grrr.

@charris

charris commented Sep 1, 2018

Copy link
Copy Markdown
Member

They may have changed their testing environment, although why it only affects the one test escapes me.

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

Yeah, not sure what is going on with that test; restarting certainly doesn't seem helpful.

@charris

charris commented Sep 1, 2018

Copy link
Copy Markdown
Member

I'm going to try closing and reopening to see if that makes a difference.

@charris charris closed this Sep 1, 2018
@charris charris reopened this Sep 1, 2018
Comment thread numpy/core/src/multiarray/datetime.c Outdated

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't this be done as else if with the error return alone in an else section?

@charris

charris commented Sep 1, 2018

Copy link
Copy Markdown
Member

Looks like the test is missing a path.

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

I tried to address the revisions & rebase on latest master for ci issue; let's see what it says I guess.

@charris

charris commented Sep 2, 2018

Copy link
Copy Markdown
Member

rebase on latest master for ci issue

I'm not convinced I actually fixed it, it may be that there is a badly configured machine out there and we are having a lucky streak of not running on it.

np.timedelta64(123, unit))
else:
assert_equal(np.timedelta64(np.int64(123)),
np.timedelta64(123))

@eric-wieser eric-wieser Sep 6, 2018 •

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.

I'm not sure allowing default units to be implied is a good idea. Is there precedent for this in datetime64?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can you clarify? np.timedelta64(123) already casts to the default m8 in the master branch; the code to handle a np.int64(123) in the same way is just duplicating that logic for another kind of integer input--it is an actual copy-paste of code for regular Python integer handling farther up.

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

One issue may simply be that we're hesitant to bake in new support for things in datetime64; I've tried to hold off on any more datetime64 PRs beyond the initial batch from a few weeks ago.

@shoyer shoyer 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, thanks!

*out = NPY_DATETIME_NAT;
return 0;
}
else if (PyArray_IsScalar(obj, Integer)) {

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.

Move this branch up, next to the branch handling "raw integers" on line 2661?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This causes test failures in my hands -- I'm guessing other types of inputs get drawn in to the branch too early if moved up there.

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.

Hmm. I bet this is due to #10685.

OK then, this looks good to me then.

@shoyer
shoyer merged commit ed64256 into numpy:master Oct 19, 2018
@shoyer

shoyer commented Oct 19, 2018

Copy link
Copy Markdown
Member

thanks @tylerjereddy !

@tylerjereddy
tylerjereddy deleted the issue_7617 branch October 19, 2018 16:24
@nicoabie

nicoabie commented Dec 6, 2018

Copy link
Copy Markdown

@tylerjereddy @shoyer I don't see this pull request in the changelogs. I'm currently running with v1.15.4 and it fails if I attempt to convert a int64 into a timedelta. is this possible? Thanks in advance

@shoyer

shoyer commented Dec 6, 2018

Copy link
Copy Markdown
Member

I don't think this was backported to the NumPy 1.15 branch. You'll need to wait for NumPy 1.16 (maybe only a few weeks?)

@nicoabie

nicoabie commented Dec 6, 2018

Copy link
Copy Markdown

@shoyer thanks for the fast response. I thought It should be there because it was merged prior to v1.15.3 but I have no problem to wait, I'll just wrap it with int(). Thanks again!

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.

5 participants