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: Package pytz not included #11974

Closed
2 tasks done
thiagola92 opened this issue May 8, 2024 · 5 comments
Closed
2 tasks done

Python: Package pytz not included #11974

thiagola92 opened this issue May 8, 2024 · 5 comments
Labels
expected behavior The behavior described in the issue is expected needs triage

Comments

@thiagola92
Copy link

thiagola92 commented May 8, 2024

What happens?

Can't use current_timestamp with duckdb python package.
Not sure if this is intended.

To Reproduce

import duckdb
duckdb.execute("SELECT current_timestamp").fetchone()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
duckdb.duckdb.InvalidInputException: Invalid Input Error: Required module 'pytz' failed to import, due to the following Python exception:
ModuleNotFoundError: No module named 'pytz'

Solution:
pip install pytz

import duckdb
duckdb.execute("SELECT current_timestamp").fetchone()
(datetime.datetime(2024, 5, 8, 6, 57, 59, 485000, tzinfo=<DstTzInfo 'America/Sao_Paulo' -03-1 day, 21:00:00 STD>),)

OS:

Ubuntu 23.10, 64-bit, X11, Linux 6.5.0-28-generic

DuckDB Version:

0.10.2

DuckDB Client:

Python 3.11.6

Full Name:

Thiago Lages de Alencar

Affiliation:

None (looking for job)

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
@Tishj
Copy link
Contributor

Tishj commented May 8, 2024

Yes that's intended:

		if (type.id() == LogicalTypeId::TIMESTAMP_TZ) {
			// We have to add the timezone info
			auto tz_utc = import_cache.pytz.timezone()("UTC");
			auto timestamp_utc = tz_utc.attr("localize")(py_timestamp);
			auto tz_info = import_cache.pytz.timezone()(client_properties.time_zone);
			return timestamp_utc.attr("astimezone")(tz_info);
		}

We need pytz to be able to convert the value to the right python type

@thiagola92
Copy link
Author

thiagola92 commented May 8, 2024

Sorry, I meant "It's intended not being included in the package?"
Taking in count that duckdb is suppose to be light, this would make sense but I wasn't sure.

@Tishj
Copy link
Contributor

Tishj commented May 8, 2024

Yes that's intended, we don't include dependencies in the package
You could circumvent this issue by casting the TIMESTAMPTZ column to VARCHAR, or TIMESTAMP if you prefer not to install pytz

@szarnyasg szarnyasg added the expected behavior The behavior described in the issue is expected label May 8, 2024
@thiagola92
Copy link
Author

Yes that's intended, we don't include dependencies in the package You could circumvent this issue by casting the TIMESTAMPTZ column to VARCHAR, or TIMESTAMP if you prefer not to install pytz

No problem at all, I can totally install pytz.
For some reason I though that datetime conversion would be standard and was not expecting an error.

As this is expected, I'm closing this.

@soerenwolfers
Copy link

@Tishj what's the reason for not specifying dependencies, if I may ask? Users that don't want dependencies to be installed can already use --no-deps in pip or equivalent options elsewhere. Alternatively, you could provide a duckdb[full] installation option for users to opt into dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expected behavior The behavior described in the issue is expected needs triage
Projects
None yet
Development

No branches or pull requests

4 participants