Skip to content

WIP, ENH: Buffer Support for DateTime Array - #15309

Closed
WillAyd wants to merge 2 commits into
numpy:masterfrom
WillAyd:datetime-buffer
Closed

WillAyd wants to merge 2 commits into
numpy:masterfrom
WillAyd:datetime-buffer

Conversation

@WillAyd

@WillAyd WillAyd commented Jan 10, 2020

Copy link
Copy Markdown
Contributor

closes #4983

I don't believe this is mergeable in current state but hoping that this is moving in the right direction.

Currently this allows writing of datetime arrays as their integer values but round-tripping is not really possible. I think what we might want to do instead is add a format for a struct that contains the value and information around the precision, so something like i:val:2c:unit (untested)

@eric-wieser

Copy link
Copy Markdown
Member

I think what we might want to do instead is add a format for a struct that contains the value and information around the precision

Added a comment with an idea about that at #4983 (comment)

@seberg

seberg commented Jan 10, 2020

Copy link
Copy Markdown
Member

I have to confess that I will need a lot of convincing to put this in. This is because it loses information so we should not be doing it silently in my opinion. If someone has a C-function which makes sense for int64, there is no guarantee that it will do something sensible for datetimes, but this way any such (e.g. cython) function will just accept it happily.

Erics suggestion may be an option (although quite frankly, it is may be too much complexity for my liking; Maybe we should rather think about growing the buffer protocol). But: at least such a hack gives you a strange datatype that the consumer will not accidentally interpret as an int64 even though it is not really one.
OTOH, the suggestion at least somewhat encompasses possible future use cases where you could have say quaternion as a named, specialized, structured (like) dtype...

@WillAyd

WillAyd commented Jan 10, 2020 •

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! @seberg what do you mean by "growing the buffer protocol"? I'm not as super well versed in this as you both, but IIUC what @eric-wieser is saying we could in theory leverage the existing format specifiers to disambiguate this from integer values (?)

@seberg

seberg commented Jan 10, 2020

Copy link
Copy Markdown
Member

What I mean is ammend/createa Python Enhancement Proposal with the idea to somehow encompass more specialized types. Although I have no idea how that could look like...

@charris charris changed the title Buffer Support for DateTime Array WIP, ENH: Buffer Support for DateTime Array Jan 15, 2020
@WillAyd

WillAyd commented Jan 16, 2020

Copy link
Copy Markdown
Contributor Author

closing for now but thanks for the insights. Will think through and re-open if something better comes to mind

@WillAyd WillAyd closed this Jan 16, 2020
@WillAyd
WillAyd deleted the datetime-buffer branch September 5, 2023 17:49
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.

datetime64 arrays don't support buffer protocol

4 participants