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

Use np.int64 type for day to nanosecond conversion (NEP50) #922

Merged
merged 2 commits into from
May 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use np.int64 type for day to nanosecond conversion (NEP50)
bnavigator committed May 3, 2024
commit b4b2c1a1e4a21099c236e679d89d97d3fca5443c
9 changes: 5 additions & 4 deletions fastparquet/converted_types.py
Original file line number Diff line number Diff line change
@@ -31,8 +31,9 @@ def unbson(x):
def tobson(x):
raise ImportError("BSON not found")

DAYS_TO_MILLIS = 86400000000000
"""Number of millis in a day. Used to convert a Date to a date"""
# Explicitly use numpy type in order to avoid promotion errors due to NEP 50 in numpy >= 2
DAYS_TO_NANOS = np.int64(86400000000000)
"""Number of nanoseconds in a day. Used to convert a Date to a date"""
nat = np.datetime64('NaT').view('int64')

simple = {
@@ -158,7 +159,7 @@ def convert(data, se, timestamp96=True, dtype=None):
if se.type == parquet_thrift.Type.INT96 and timestamp96:
data2 = data.view([('ns', 'i8'), ('day', 'i4')])
# TODO: this should be ms unit, now that we can?
return ((data2['day'] - 2440588) * 86400000000000 +
return ((data2['day'] - np.int64(2440588)) * DAYS_TO_NANOS +
data2['ns']).view('M8[ns]')
if se.logicalType is not None and se.logicalType.TIMESTAMP is not None:
dt = _logical_to_time_dtype(se.logicalType.TIMESTAMP)
@@ -188,7 +189,7 @@ def convert(data, se, timestamp96=True, dtype=None):
for i in range(len(data))
])
elif ctype == parquet_thrift.ConvertedType.DATE:
data = data * DAYS_TO_MILLIS
data = data * DAYS_TO_NANOS
return data.view('datetime64[ns]')
elif ctype == parquet_thrift.ConvertedType.TIME_MILLIS:
# this was not covered by new pandas time units