{"id":1406,"library":"bottleneck","title":"Bottleneck","description":"Bottleneck is a Python library that provides a collection of fast, C-optimized functions for NumPy arrays, particularly useful for operations involving NaNs (Not a Number). It aims to offer significant performance improvements over equivalent NumPy functions for large arrays by implementing them in C. The current version is 1.6.0, with releases generally following significant NumPy updates or critical bug fixes, ensuring compatibility and performance.","status":"active","version":"1.6.0","language":"en","source_language":"en","source_url":"https://github.com/pydata/bottleneck","tags":["numpy","performance","array_operations","c_extensions","data_science"],"install":[{"cmd":"pip install bottleneck","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Core functionality relies on NumPy arrays and C API for data structures and fundamental operations.","package":"numpy","optional":false}],"imports":[{"symbol":"bottleneck","correct":"import bottleneck as bn"}],"quickstart":{"code":"import numpy as np\nimport bottleneck as bn\n\na = np.array([1.0, 2.0, np.nan, 4.0])\nb = np.arange(12.0).reshape(3, 4)\nb[0, 0] = np.nan\n\nprint(f\"Original array a: {a}\")\nprint(f\"bn.nansum(a): {bn.nansum(a)}\")\n\nprint(f\"\\nOriginal array b:\\n{b}\")\nprint(f\"bn.nanmean(b, axis=1): {bn.nanmean(b, axis=1)}\")","lang":"python","description":"This example demonstrates how to import bottleneck as 'bn' and use its NaN-aware functions, such as `nansum` and `nanmean`, on NumPy arrays for potentially faster computation."},"warnings":[{"fix":"Always test `bottleneck` functions against `numpy` for critical numerical precision requirements to ensure the minor differences are acceptable for your application.","message":"Results from bottleneck functions might differ slightly from NumPy equivalents due to distinct algorithms and floating-point arithmetic. This is generally within acceptable numerical precision but could be a concern for highly sensitive applications.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Profile your code with both `bottleneck` and `numpy` for your specific array sizes and operations to confirm `bottleneck` provides a benefit in your use case.","message":"Performance gains from bottleneck are primarily noticeable for large arrays and specific operations (especially those handling NaNs). For small arrays, the overhead of calling the C extension might negate or even reverse performance benefits compared to pure NumPy.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your Python environment is version 3.10 or newer. If you must use an older Python version, refer to bottleneck's historical documentation for compatible versions (e.g., 1.3.2 for Python 3.7+).","message":"Bottleneck 1.x series (including 1.6.0) requires Python 3.10 or newer. Installing on older Python versions will fail.","severity":"breaking","affected_versions":"1.4.0+"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}