8000 BUG: MaskedArray.astype('uint8') with certain fill_value raises warning on ARM (Mac M3) inside Docker (Ubuntu 24.04/25.04) and leads inconsistent output · Issue #28403 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: MaskedArray.astype('uint8') with certain fill_value raises warning on ARM (Mac M3) inside Docker (Ubuntu 24.04/25.04) and leads inconsistent output #28403

@AlessioChecchin

Description

@AlessioChecchin

Describe the issue:

I encountered a warning when converting a MaskedArray to uint8 inside a Docker container running Ubuntu 24.04 or 25.04 on an Apple M3 Mac. The same code runs fine on:

  • macOS (outside Docker, on M3)
  • Windows WSL2 with Ubuntu 22.04 (both inside and outside Docker)

However, inside Docker (Ubuntu 24.04 or 25.04 on ARM), the following script produces a warning:

import numpy as np

foo = np.ma.masked_equal(np.arange(10, dtype="float32"), 5)
foo.fill_value = -1.0
bar = foo.astype("uint8")  # Generates a warning
print(bar.fill_value)
bar.fill_value = 255
print(bar.fill_value)
print(bar.filled().dtype)

Note that i found this script on another issue that was caused by another bug and seems solved.

Expected Behavior:
The script should execute without warnings, as it does on other platforms and the output shoud be consistent.
Here is the output that i got from all other platforms.

255
255
uint8

Actual Behavior:
A warning is raised when calling astype("uint8") when running in Docker on ARM.
I also noted that print(bar.fill_value) prints 0 only in Docker ARM

/opt/venv/lib/python3.13/site-packages/numpy/ma/core.py:502: RuntimeWarning: invalid value encountered in cast
  fill_value = np.asarray(fill_value, dtype=ndtype)
0
255
uint8
2.2.3

System information

  • Numpy version: 2.2.3
  • Docker: Ubuntu 24.04 or 25.04
  • Host system: macOS (Apple M3, ARM64)
  • np.show_config()
{
  "Compilers": {
    "c": {
      "name": "gcc",
      "linker": "ld.bfd",
      "version": "10.2.1",
      "commands": "cc"
    },
    "cython": {
      "name": "cython",
      "linker": "cython",
      "version": "3.0.12",
      "commands": "cython"
    },
    "c++": {
      "name": "gcc",
      "linker": "ld.bfd",
      "version": "10.2.1",
      "commands": "c++"
    }
  },
  "Machine Information": {
    "host": {
      "cpu": "aarch64",
      "family": "aarch64",
      "endian": "little",
      "system": "linux"
    },
    "build": {
      "cpu": "aarch64",
      "family": "aarch64",
      "end
78D7
ian": "little",
      "system": "linux"
    }
  },
  "Build Dependencies": {
    "blas": {
      "name": "scipy-openblas",
      "found": true,
      "version": "0.3.28",
      "detection method": "pkgconfig",
      "include directory": "/opt/_internal/cpython-3.13.0/lib/python3.13/site-packages/scipy_openblas64/include",
      "lib directory": "/opt/_internal/cpython-3.13.0/lib/python3.13/site-packages/scipy_openblas64/lib",
      "openblas configuration": "OpenBLAS 0.3.28  USE64BITINT DYNAMIC_ARCH NO_AFFINITY neoversen1 MAX_THREADS=64",
      "pc file directory": "/project/.openblas"
    },
    "lapack": {
      "name": "scipy-openblas",
      "found": true,
      "version": "0.3.28",
      "detection method": "pkgconfig",
      "include directory": "/opt/_internal/cpython-3.13.0/lib/python3.13/site-packages/scipy_openblas64/include",
      "lib directory": "/opt/_internal/cpython-3.13.0/lib/python3.13/site-packages/scipy_openblas64/lib",
      "openblas configuration": "OpenBLAS 0.3.28  USE64BITINT DYNAMIC_ARCH NO_AFFINITY neoversen1 MAX_THREADS=64",
      "pc file directory": "/project/.openblas"
    }
  },
  "Python Information": {
    "path": "/tmp/build-env-tttxdu3h/bin/python",
    "version": "3.13"
  },
  "SIMD Extensions": {
    "baseline": [
      "NEON",
      "NEON_FP16",
      "NEON_VFPV4",
      "ASIMD"
    ],
    "found": [
      "ASIMDHP",
      "ASIMDFHM"
    ],
    "not found": [
      "SVE"
    ]
  }
}

Additional Notes:

  • The issue does not occur on Windows WSL2 (Intel i9 13900) or macOS native (M3).

I also took note of the .whl files:

  • WSL2 running Ubuntu 22.04: numpy-2.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • WSL2 running Ubuntu 22.04 + Docker running Ubuntu 25.05: numpy-2.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • macOS native (M3): numpy-2.2.3-cp312-cp312-macosx_14_0_arm64.whl
  • macOS + Docker running Ubuntu 25.05: numpy-2.2.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Reproduce the code example:

import numpy as np

foo = np.ma.masked_equal(np.arange(10, dtype="float32"), 5)
foo.fill_value = -1.0
bar = foo.astype("uint8")  # Generates a warning
print(bar.fill_value)
bar.fill_value = 255
print(bar.fill_value)
print(bar.filled().dtype)

Python and NumPy Versions:

3.13.2 (main, Feb 5 2025, 01:23:35) [GCC 14.2.0]

Runtime Environment:

[{
  'numpy_version': '2.2.3',
  'python': '3.13.2 (main, Feb  5 2025, 01:23:35) [GCC 14.2.0]',
  'uname': uname_result(system='Linux', node='4bcdb1f2c3ec', release='6.10.14-linuxkit', version='#1 SMP Fri Nov 29 17:22:03 UTC 2024', machine='aarch64')
},
{'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'], 'found': ['ASIMDHP', 'ASIMDFHM'], 'not_found': ['SVE']}},
{
  'architecture': 'neoversen1',
  'filepath': '/opt/venv/lib/python3.13/site-packages/numpy.libs/libscipy_openblas64_-48fd33d4.so',
  'internal_api': 'openblas',
  'num_threads': 11,
  'prefix': 'libscipy_openblas',
  'threading_layer': 'pthreads',
  'user_api': 'blas',
  'version': '0.3.28'
}]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0