Skip to content

ARROW-722: [Python] Support additional date/time types and metadata, conversion to/from NumPy and pandas.DataFrame - #510

Closed
wesm wants to merge 5 commits into
apache:masterfrom
wesm:ARROW-722
Closed

wesm wants to merge 5 commits into
apache:masterfrom
wesm:ARROW-722

Conversation

@wesm

@wesm wesm commented Apr 8, 2017

Copy link
Copy Markdown
Member

Would appreciate a close look from @xhochy, @cpcloud. Also did some inline visitor cleaning for nicer code reuse

wesm added 2 commits April 9, 2017 15:26
… creation

from same-size int32/64. Use inline visitor in PandasConverter
Change-Id: Ia9e2005448c2ec5280a5a8507bc37ee276555807
@wesm

wesm commented Apr 9, 2017

Copy link
Copy Markdown
Member Author

Rebased

Comment thread cpp/src/arrow/python/builtin_convert.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this and the above use InvalidConversion?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread cpp/src/arrow/python/pandas_convert.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it make sense to have a constant NANOS_PER_DAY?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And generally speaking to have a header with some constants for readability with things like npy_shift.

Comment thread cpp/src/arrow/python/pandas_convert.cc Outdated
} else if (PyDate_CheckExact(objects[i])) {
return ConvertDates();
// We could choose Date32 or Date64
return ConvertDates<Date64Type>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thinking about this again, I wonder if Date32Type is the better choice here. It's smaller and still compatible with pandas and numpy. I think from a user's perspective they don't actually care, they just want it to be fast, correct and easily interoperable with existing systems. If 32 bit dates can satisfy those constraints just as easily as 64 bits, it might make more sense to go with 32.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, this makes things more in line with Feather, too. Changing it

Comment thread cpp/src/arrow/python/pandas_convert.cc Outdated
template <typename Type>
typename std::enable_if<std::is_base_of<TimeType, Type>::value, Status>::type Visit(
const Type& type) {
return Status::NotImplemented("time type");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this should say "Don't know how to serialize Arrow time type to NumPy" or something that's a little more indicative of where the failure is happening.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread python/pyarrow/scalar.pyx

# Shift to seconds since epoch
return datetime.datetime.utcfromtimestamp(
int(ap.Value(self.index)) * 86400).date()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it necessary to cast this to int here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I got burned here because ap.Value returns int32_t and multiplying by 86400 caused an overflow

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool

@cpcloud

cpcloud commented Apr 9, 2017

Copy link
Copy Markdown
Contributor

Nothing major, just thinking a bit about the 32 vs 64 choice for Date types. Otherwise looks good.

wesm added 3 commits April 9, 2017 16:36
Change-Id: I8528eb0ea1ae95c30e3a2636ca1b5ad86e087730
Change-Id: Idc98f25c0da2565975d56f44748f666ca201f84a
Change-Id: Ibec06a1dbe494e450de59e3fcd63f3222b44e5d9
@wesm

wesm commented Apr 9, 2017

Copy link
Copy Markdown
Member Author

OK, I'll merge this once the build runs

@asfgit asfgit closed this in 137aade Apr 10, 2017
@wesm
wesm deleted the ARROW-722 branch April 10, 2017 00:01

if (type == Type::DATE64) {
if (type == Type::DATE32) {
// Date64Type is millisecond timestamp stored as int64_t

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.

Comment does not match the called code.

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.

3 participants