From 66220c71e73f94cd73dc2b5fab4925c9119f75a8 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:07:36 -0500 Subject: [PATCH] refactor(clickhouse): clean up session timezone handling --- ibis/backends/clickhouse/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ibis/backends/clickhouse/__init__.py b/ibis/backends/clickhouse/__init__.py index 080c182879e2..b5f90b64f47d 100644 --- a/ibis/backends/clickhouse/__init__.py +++ b/ibis/backends/clickhouse/__init__.py @@ -3,7 +3,6 @@ import ast import atexit import glob -import warnings from contextlib import closing, suppress from functools import partial from typing import TYPE_CHECKING, Any, Literal @@ -123,6 +122,7 @@ def do_connect( client_name: str = "ibis", secure: bool | None = None, compression: str | bool = True, + settings: Mapping[str, Any] | None = None, **kwargs: Any, ): """Create a ClickHouse client for use with Ibis. @@ -148,6 +148,8 @@ def do_connect( The kind of compression to use for requests. See https://clickhouse.com/docs/en/integrations/python#compression for more information. + settings + ClickHouse session settings kwargs Client specific keyword arguments @@ -158,6 +160,10 @@ def do_connect( >>> client """ + if settings is None: + settings = {} + settings.setdefault("session_timezone", "UTC") + self.con = cc.get_client( host=host, # 8123 is the default http port 443 is https @@ -170,11 +176,6 @@ def do_connect( compress=compression, **kwargs, ) - try: - with closing(self.raw_sql("SET session_timezone = 'UTC'")): - pass - except Exception as e: # noqa: BLE001 - warnings.warn(f"Could not set timezone to UTC: {e}", category=UserWarning) self._temp_views = set() @property