@@ -68,7 +68,7 @@ def __init__(self,
68
68
self .uri = uri
69
69
self ._init_common_settings (apply_server_timezone )
70
70
71
- def _init_common_settings (self , apply_server_timezone :Optional [Union [str , bool ]] ):
71
+ def _init_common_settings (self , apply_server_timezone : Optional [Union [str , bool ]]):
72
72
self .server_tz , dst_safe = pytz .UTC , True
73
73
self .server_version , server_tz = \
74
74
tuple (self .command ('SELECT version(), timezone()' , use_database = False ))
@@ -122,14 +122,16 @@ def _validate_settings(self, settings: Optional[Dict[str, Any]]) -> Dict[str, st
122
122
return validated
123
123
124
124
def _validate_setting (self , key : str , value : Any , invalid_action : str ) -> Optional [str ]:
125
- new_value = str (value )
125
+ str_value = str (value )
126
126
if value is True :
127
- new_value = '1'
127
+ str_value = '1'
128
128
elif value is False :
129
- new_value = '0'
129
+ str_value = '0'
130
130
if key not in self .valid_transport_settings :
131
131
setting_def = self .server_settings .get (key )
132
- if setting_def is None or (setting_def .readonly and setting_def .value != new_value ):
132
+ if setting_def and setting_def .value == str_value :
133
+ return None # don't send settings that are already the expected value
134
+ if setting_def is None or setting_def .readonly :
133
135
if key in self .optional_transport_settings :
134
136
return None
135
137
if invalid_action == 'send' :
@@ -139,7 +141,7 @@ def _validate_setting(self, key: str, value: Any, invalid_action: str) -> Option
139
141
return None
140
142
else :
141
143
raise ProgrammingError (f'Setting { key } is unknown or readonly' ) from None
142
- return new_value
144
+ return str_value
143
145
144
146
def _setting_status (self , key : str ) -> SettingStatus :
145
147
comp_setting = self .server_settings .get (key )
@@ -342,6 +344,7 @@ def query_np(self,
342
344
create_query_context method
343
345
:return: Numpy array representing the result set
344
346
"""
347
+ check_numpy ()
345
348
return self ._context_query (locals (), use_numpy = True ).np_result
346
349
347
350
# pylint: disable=duplicate-code,too-many-arguments,unused-argument
@@ -361,6 +364,7 @@ def query_np_stream(self,
361
364
create_query_context method
362
365
:return: Generator that yield a numpy array per block representing the result set
363
366
"""
367
+ check_numpy ()
364
368
return self ._context_query (locals (), use_numpy = True , streaming = True ).np_stream
365
369
366
370
# pylint: disable=duplicate-code,unused-argument
@@ -384,6 +388,7 @@ def query_df(self,
384
388
create_query_context method
385
389
:return: Pandas dataframe representing the result set
386
390
"""
391
+ check_pandas ()
387
392
return self ._context_query (locals (), use_numpy = True , as_pandas = True ).df_result
388
393
389
394
# pylint: disable=duplicate-code,unused-argument
@@ -407,6 +412,7 @@ def query_df_stream(self,
407
412
create_query_context method
408
413
:return: Generator that yields a Pandas dataframe per block representing the result set
409
414
"""
415
+ check_pandas ()
410
416
return self ._context_query (locals (), use_numpy = True ,
411
417
as_pandas = True ,
412
418
streaming = True ).df_stream
@@ -519,6 +525,7 @@ def query_arrow(self,
519
525
:param external_data ClickHouse "external data" to send with query
520
526
:return: PyArrow.Table
521
527
"""
528
+ check_arrow ()
522
529
settings = self ._update_arrow_settings (settings , use_strings )
523
530
return to_arrow (self .raw_query (query ,
524
531
parameters ,
@@ -541,6 +548,7 @@ def query_arrow_stream(self,
541
548
:param external_data ClickHouse "external data" to send with query
542
549
:return: Generator that yields a PyArrow.Table for per block representing the result set
543
550
"""
551
+ check_arrow ()
544
552
settings = self ._update_arrow_settings (settings , use_strings )
545
553
return to_arrow_batches (self .raw_stream (query ,
546
554
parameters ,
@@ -661,6 +669,7 @@ def insert_df(self, table: str = None,
661
669
different data batches
662
670
:return: QuerySummary with summary information, throws exception if insert fails
663
671
"""
672
+ check_pandas ()
664
673
if context is None :
665
674
if column_names is None :
666
675
column_names = df .columns
@@ -686,6 +695,7 @@ def insert_arrow(self, table: str,
686
695
:param settings: Optional dictionary of ClickHouse settings (key/string values)
687
696
:return: QuerySummary with summary information, throws exception if insert fails
688
697
"""
698
+ check_arrow ()
689
699
full_table = table if '.' in table or not database else f'{ database } .{ table } '
690
700
compression = self .write_compression if self .write_compression in ('zstd' , 'lz4' ) else None
691
701
column_names , insert_block = arrow_buffer (arrow_table , compression )
0 commit comments