This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch pyclient_timestamp_type in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit e4c64215200ac6d383d96b578d27e515693e26d7 Author: HTHou <[email protected]> AuthorDate: Tue Apr 22 16:53:13 2025 +0800 add fall back logic --- iotdb-client/client-py/iotdb/utils/Field.py | 5 +++-- iotdb-client/client-py/iotdb/utils/iotdb_rpc_dataset.py | 6 +++--- iotdb-client/client-py/iotdb/utils/rpc_utils.py | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/iotdb-client/client-py/iotdb/utils/Field.py b/iotdb-client/client-py/iotdb/utils/Field.py index b0622cafebe..5ff2baa01f0 100644 --- a/iotdb-client/client-py/iotdb/utils/Field.py +++ b/iotdb-client/client-py/iotdb/utils/Field.py @@ -19,6 +19,7 @@ # for package from iotdb.utils.IoTDBConstants import TSDataType from iotdb.tsfile.utils.date_utils import parse_int_to_date +from iotdb.utils.rpc_utils import convert_to_timestamp import numpy as np import pandas as pd @@ -168,7 +169,7 @@ class Field(object): or self.value is pd.NA ): return None - return pd.Timestamp(self.value, unit=self.__precision, tz=self.__timezone) + return convert_to_timestamp(self.value, self.__precision, self.__timezone) def get_date_value(self): if self.__data_type is None: @@ -214,7 +215,7 @@ class Field(object): elif data_type == 4: return np.float64(self.value) elif data_type == 8: - return pd.Timestamp(self.value, unit=self.__precision, tz=self.__timezone) + return convert_to_timestamp(self.value, self.__precision, self.__timezone) elif data_type == 9: return parse_int_to_date(self.value) elif data_type == 5 or data_type == 11: diff --git a/iotdb-client/client-py/iotdb/utils/iotdb_rpc_dataset.py b/iotdb-client/client-py/iotdb/utils/iotdb_rpc_dataset.py index 912ee41595f..ee2e02d8cdc 100644 --- a/iotdb-client/client-py/iotdb/utils/iotdb_rpc_dataset.py +++ b/iotdb-client/client-py/iotdb/utils/iotdb_rpc_dataset.py @@ -28,7 +28,7 @@ from iotdb.tsfile.utils.date_utils import parse_int_to_date from iotdb.tsfile.utils.tsblock_serde import deserialize from iotdb.utils.exception import IoTDBConnectionException from iotdb.utils.IoTDBConstants import TSDataType -from iotdb.utils.rpc_utils import verify_success +from iotdb.utils.rpc_utils import verify_success, convert_to_timestamp logger = logging.getLogger("IoTDB") TIMESTAMP_STR = "Time" @@ -285,8 +285,8 @@ class IoTDBRpcDataSet(object): elif data_type == 8: data_array = pd.Series( [ - pd.Timestamp( - x, unit=self.__time_precision, tz=self.__zone_id + convert_to_timestamp( + x, self.__time_precision, self.__zone_id ) for x in column_array ] diff --git a/iotdb-client/client-py/iotdb/utils/rpc_utils.py b/iotdb-client/client-py/iotdb/utils/rpc_utils.py index 5023b0de459..b519499456b 100644 --- a/iotdb-client/client-py/iotdb/utils/rpc_utils.py +++ b/iotdb-client/client-py/iotdb/utils/rpc_utils.py @@ -15,12 +15,16 @@ # specific language governing permissions and limitations # under the License. # +import logging + import pandas as pd from tzlocal import get_localzone_name from iotdb.thrift.common.ttypes import TSStatus from iotdb.utils.exception import RedirectException, StatementExecutionException +logger = logging.getLogger("IoTDB") + SUCCESS_STATUS = 200 MULTIPLE_ERROR = 302 REDIRECTION_RECOMMEND = 400 @@ -76,4 +80,8 @@ def convert_to_timestamp(time: int, precision: str, timezone: str): try: return pd.Timestamp(time, unit=precision, tz=timezone) except ValueError: + logger.warning( + f"Timezone string '{timezone}' cannot be recognized by pandas. " + f"Falling back to local timezone: '{get_localzone_name()}'." + ) return pd.Timestamp(time, unit=precision, tz=get_localzone_name())
