From bd6bf4b3d7f69b8a986c0581e1ae944b8fc56878 Mon Sep 17 00:00:00 2001 From: Hanjaemin-Kr <83811627+HanJaemin-kr@users.noreply.github.com> Date: Thu, 3 Dec 2026 00:01:42 +0900 Subject: [PATCH] fix(write): avoid loading NumPy on client import --- CHANGELOG.md | 1 + influxdb_client/client/write/point.py | 14 ++++++-------- tests/test_point.py | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6d5588b..d671d0d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ 1. [#732](https://github.com/influxdata/influxdb-client-python/pull/732): Apply the `#default` annotation in `FluxCsvParser` when it comes before `#datatype`. 1. [#733](https://github.com/influxdata/influxdb-client-python/pull/733): Write the last batch when the batching `WriteApi` is closed in an `atexit` handler instead of dropping it with "cannot schedule new futures after interpreter shutdown". 1. [#734](https://github.com/influxdata/influxdb-client-python/pull/734): Match `data_frame_timestamp_column` by exact column name, so a field whose name is part of the timestamp column name (e.g. `Open` with `OpenTime`) is no longer dropped. +1. [#673](https://github.com/influxdata/influxdb-client-python/issues/673): Avoid loading NumPy when importing the client. ## 1.50.0 [2026-01-23] diff --git a/influxdb_client/client/write/point.py b/influxdb_client/client/write/point.py index cc95d204..f4d68085 100644 --- a/influxdb_client/client/write/point.py +++ b/influxdb_client/client/write/point.py @@ -36,13 +36,6 @@ '\\': r'\\', }) -try: - import numpy as np - - _HAS_NUMPY = True -except ModuleNotFoundError: - _HAS_NUMPY = False - class Point(object): """ @@ -361,7 +354,12 @@ def _convert_timestamp(timestamp, precision=DEFAULT_WRITE_PRECISION): def _np_is_subtype(value, np_type): - if not _HAS_NUMPY or not hasattr(value, 'dtype'): + if not hasattr(value, 'dtype'): + return False + + try: + import numpy as np + except ModuleNotFoundError: return False if np_type == 'float': diff --git a/tests/test_point.py b/tests/test_point.py index e799ae9c..5a54225d 100644 --- a/tests/test_point.py +++ b/tests/test_point.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import subprocess +import sys import unittest from datetime import datetime, timezone, timedelta from decimal import Decimal @@ -394,6 +396,18 @@ def test_backslash(self): "test,tag1=value1,tag2=value\2,tag3=value\\3,tag4=value\\4,tag5=value\\\\5 value=10i 1624989000000000000", point.to_line_protocol()) + def test_import_does_not_load_numpy(self): + pytest.importorskip("numpy") + + script = ( + "import sys\n" + "from influxdb_client import Point\n" + "assert 'numpy' not in sys.modules, 'Importing influxdb_client loaded NumPy'\n" + "assert Point('sample').field('value', 1).to_line_protocol() == 'sample value=1i'\n" + "assert 'numpy' not in sys.modules, 'Serializing a built-in integer loaded NumPy'\n" + ) + subprocess.run([sys.executable, "-c", script], check=True) + def test_numpy_types(self): from influxdb_client.extras import np