Skip to content

Commit acdd0e3

Browse files
eendebakptmattip
andauthored
PERF: Eliminate slow check for pypy during numpy import (numpy#22163)
This PR replaces the import of platform and a call to platform.python_implementation() with a check using sys.implementation.name to improve the numpy import time. The improvement is about 5-10 ms (system dependent). Also see numpy#22061 Co-authored-by: Matti Picus <[email protected]>
1 parent 8d45b9b commit acdd0e3

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

numpy/core/_internal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import ast
88
import re
99
import sys
10-
import platform
1110
import warnings
1211

1312
from .multiarray import dtype, array, ndarray, promote_types
@@ -16,7 +15,7 @@
1615
except ImportError:
1716
ctypes = None
1817

19-
IS_PYPY = platform.python_implementation() == 'PyPy'
18+
IS_PYPY = sys.implementation.name == 'pypy'
2019

2120
if sys.byteorder == 'little':
2221
_nbo = '<'

numpy/testing/_private/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class KnownFailureException(Exception):
4848
KnownFailureTest = KnownFailureException # backwards compat
4949
verbose = 0
5050

51-
IS_PYPY = platform.python_implementation() == 'PyPy'
51+
IS_PYPY = sys.implementation.name == 'pypy'
5252
IS_PYSTON = hasattr(sys, "pyston_version_info")
5353
HAS_REFCOUNT = getattr(sys, 'getrefcount', None) is not None and not IS_PYSTON
5454
HAS_LAPACK64 = numpy.linalg.lapack_lite._ilp64

0 commit comments

Comments
 (0)