Skip to content

fix(write): avoid loading NumPy on client import - #740

Open
HanJaemin-kr wants to merge 2 commits into
influxdata:masterfrom
HanJaemin-kr:fix/lazy-point-numpy-import
Open

HanJaemin-kr wants to merge 2 commits into
influxdata:masterfrom
HanJaemin-kr:fix/lazy-point-numpy-import

Conversation

@HanJaemin-kr

Copy link
Copy Markdown

Closes #673.

Proposed Changes

Importing influxdb_client launches NumPy's worker threads on some setups, even if the application only writes built-in Python values. Move the NumPy import into the field dtype check so those applications can import the client and write points without loading NumPy.

Testing

Added a fresh-process regression test for importing the client and serializing a built-in integer. The existing NumPy scalar tests still pass. Also wrote and read back a point containing both a Python int and a NumPy int64 against InfluxDB 2.7. The focused suite passed all 85 tests. The full local suite passed 385 tests and skipped 3. All 36 failures also reproduced on the unmodified base commit.

Manual check

With NumPy installed, run this in a fresh Python process from the checkout.

import sys

from influxdb_client import Point

assert "numpy" not in sys.modules
assert Point("sample").field("value", 1).to_line_protocol() == "sample value=1i"
assert "numpy" not in sys.modules

import numpy as np

assert Point("sample").field("value", np.int64(1)).to_line_protocol() == "sample value=1i"

Checklist

  • Updated CHANGELOG.md
  • Added a regression test
  • Full test suite passes
  • CLA confirmed

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.75%. Comparing base (354d881) to head (6ba5136).

Files with missing lines Patch % Lines
influxdb_client/client/write/point.py 80.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #740      +/-   ##
==========================================
- Coverage   90.83%   90.75%   -0.09%     
==========================================
  Files          41       41              
  Lines        3591     3590       -1     
==========================================
- Hits         3262     3258       -4     
- Misses        329      332       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import of this library starts 6 threads

2 participants