-
Notifications
You must be signed in to change notification settings - Fork 80
Error fetching data to an OracleDataFrame with dates prior to 1970-01-01 #483
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
Comments
Interestingly it doesn't reproduce for me:
This is on macOS with Python 3.12.7, python-oracledb 3.1 and 3.0, and Oracle Database 23.x. I also tried even older dates without a problem. Can you share more detail about your environment? |
The same error is happening for me. oracledb version: 3.1.0 |
@usmanjohn thanks for sharing. What's your (exact) DB version and flavor (local, cloud, exadata etc etc)? |
Hi @cjbj , The DB version is 19.12.0.0.0 and flavor is local. |
@cjbj I realised that the question name has changed. My problem no longer belongs here, there is nothing to do with the date on my code. The problem is with fetch_df_all I think. |
@usmanjohn if you have a testcase for your scenario, we'd be happy to look at it too. |
I am running on this environment: Oracle: 19.26.0.0.0 |
Looks related to this Python Windows issue: https://stackoverflow.com/questions/59199985/why-is-datetimes-timestamp-method-returning-oserror-errno-22-invalid-a. From https://docs.python.org/3/library/datetime.html#datetime.date.fromtimestamp:
|
All other methods work well, except for fetch_df_all and fetch_df_batches.
|
Not that conversion, try this: import datetime
d = datetime.datetime(1970, 1, 1)
print("to epoch:", d.timestamp()) That should generate the error you are experiencing, as that is what the conversion to dataframe is doing since it is required for the Arrow data format. This issue appears only on Windows. There are workarounds that are possible which can be investigated. For now your current "solutions" are: (a) stop using Windows!, (b) avoid the use of dates prior to 1970 or (c) convert them to string. If you are able to build yourself, you can validate one of the workarounds (untested): diff --git a/src/oracledb/impl/base/converters.pyx b/src/oracledb/impl/base/converters.pyx
index 3614a2b1..8460311b 100644
--- a/src/oracledb/impl/base/converters.pyx
+++ b/src/oracledb/impl/base/converters.pyx
@@ -243,8 +243,12 @@ cdef int convert_oracle_data_to_arrow(OracleMetadata from_metadata,
rb = &data.buffer.as_raw_bytes
arrow_array.append_bytes(<void*> rb.ptr, rb.num_bytes)
elif arrow_type == NANOARROW_TYPE_TIMESTAMP:
- ts = int(convert_date_to_python(&data.buffer).timestamp() *
- arrow_array.factor)
+ # for Windows only
+ dt = convert_date_to_python(&data.buffer)
+ epoch_date = datetime.datetime(1970, 1, 1)
+ ts = (dt - epoch_date).total_seconds() * arrow_array.factor
+# ts = int(convert_date_to_python(&data.buffer).timestamp() *
+# arrow_array.factor)
arrow_array.append_int64(ts)
elif arrow_type == NANOARROW_TYPE_DECIMAL128:
convert_number_to_arrow_decimal(arrow_array, &data.buffer) |
Same error with that code. For the proposed solutions: I am not able to build the others workarounds. Thank you for your help. |
@suraj-ora-2020 will work on a fix. |
I am using oracledb 3.1 to extract data, and an error occurs when there is any date less than or equal to 1970-01-01 in any date column.
Any date after 1970-01-01 works fine.
The code that demonstrates the problem is as follows:
Error message:
The text was updated successfully, but these errors were encountered: