Skip to content

BUG: fix repr for generic datetime - #11841

Closed
tylerjereddy wants to merge 1 commit into
numpy:masterfrom
tylerjereddy:issue_11752_datetime_generic_repr
Closed

tylerjereddy wants to merge 1 commit into
numpy:masterfrom
tylerjereddy:issue_11752_datetime_generic_repr

Conversation

@tylerjereddy

Copy link
Copy Markdown
Contributor

Fixes #11752.

Some discussion may be needed since git bisect didn't reveal a commit where one of Eric's cases didn't raise an Exception of some sort.

For example, with the changes here, instead of repr crashing we get NaT as filler:

repr(np.zeros(2, np.datetime64))
# "array(['NaT', 'NaT'], dtype=datetime64)"

As a reference:

repr(np.zeros(2, 'datetime64[M]'))
# "array(['1970-01', '1970-01'], dtype='datetime64[M]')"

* NaT is now used as the filler
element for NumPy array reprs
with generic datetime64 type;
previously the repr would cause
a crash
@tylerjereddy

Copy link
Copy Markdown
Contributor Author

@eric-wieser Is this the behavior you had in mind? Should I bring it up on the mailing list?

@eric-wieser

eric-wieser commented Sep 27, 2018 •

Copy link
Copy Markdown
Member

Does this change the result of the following to not give an error?

np.array([2], np.uint64).view('M8')

If so, that might lead to weird behavior for

is_nat = np.array([2], np.uint64).view('M8')
is_not_nat = is_nat.view('m8')

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

@eric-wieser Yes, ValueError on master and ['NaT'] on tip of this PR branch.

The timedelta view will restore the original [2], yes. It is the same thing as np.array([2], np.uint64).view('m8') on master though & docs indicate that for a.view(some_dtype)

This can cause a reinterpretation of the bytes of memory.

Are you proposing to raise an error or warning on the view?

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

No clear route forward / evidence of priority -- so closing my own PR here.

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.

2 participants