Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Implement casts from timestamp to date32/date64 and support in Array.from_pandas #15613

Closed
asfimport opened this issue Oct 23, 2017 · 4 comments

Comments

@asfimport
Copy link

asfimport commented Oct 23, 2017

When calling Array.from_pandas with a pandas.Series of dates and specifying the desired pyarrow type, an error occurs. If the type is not specified then from_pandas will interpret the data as a timestamp type.

import pandas as pd
import pyarrow as pa
import datetime

arr = pa.array([datetime.date(2017, 10, 23)])
c = pa.Column.from_array("d", arr)

s = c.to_pandas()
print(s)
# 0   2017-10-23
# Name: d, dtype: datetime64[ns]

result = pa.Array.from_pandas(s, type=pa.date32())
print(result)
"""
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyarrow/array.pxi", line 295, in pyarrow.lib.Array.__repr__ (/home/bryan/git/arrow/python/build/temp.linux-x86_64-2.7/lib.cxx:26221)
  File "/home/bryan/.local/lib/python2.7/site-packages/pyarrow-0.7.2.dev21+ng028f2cd-py2.7-linux-x86_64.egg/pyarrow/formatting.py", line 28, in array_format
    values.append(value_format(x, 0))
  File "/home/bryan/.local/lib/python2.7/site-packages/pyarrow-0.7.2.dev21+ng028f2cd-py2.7-linux-x86_64.egg/pyarrow/formatting.py", line 49, in value_format
    return repr(x)
  File "pyarrow/scalar.pxi", line 63, in pyarrow.lib.ArrayValue.__repr__ (/home/bryan/git/arrow/python/build/temp.linux-x86_64-2.7/lib.cxx:19535)
  File "pyarrow/scalar.pxi", line 137, in pyarrow.lib.Date32Value.as_py (/home/bryan/git/arrow/python/build/temp.linux-x86_64-2.7/lib.cxx:20368)
ValueError: year is out of range
"""

Reporter: Bryan Cutler / @BryanCutler
Assignee: Wes McKinney / @wesm

Related issues:

PRs and other links:

Note: This issue was originally created as ARROW-1718. Please see the migration documentation for further details.

@asfimport
Copy link
Author

Bryan Cutler / @BryanCutler:
@wesm I am also wondering if Column.to_pandas from the code above should produce a 'datetime64[ns]' series? I believe Array.to_pandas creates a 'datetime64[D]' series.

@asfimport
Copy link
Author

Wes McKinney / @wesm:
That sounds inconsistent. Will have to take a closer look

@asfimport
Copy link
Author

Wes McKinney / @wesm:
There's a bit of work to do here but it will be for the greater good. I changed the title to reflect the scope of the work (which is more than a bugfix). Should have a patch out in the next few days

@asfimport
Copy link
Author

Uwe Korn / @xhochy:
Issue resolved by pull request 1258
#1258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants