Return the name of the public NumPy function that called ``__array_wrap__``, or None if the caller is not NumPy. Depending on the NumPy version, private helpers (``_wrapfunc``, ``_wrapit``) may sit between the public function and ``__array_wrap__``; skip them.
()
| 310 | |
| 311 | |
| 312 | def _wrapped_numpy_funcname() -> str | None: |
| 313 | """Return the name of the public NumPy function that called ``__array_wrap__``, |
| 314 | or None if the caller is not NumPy. |
| 315 | |
| 316 | Depending on the NumPy version, private helpers (``_wrapfunc``, ``_wrapit``) |
| 317 | may sit between the public function and ``__array_wrap__``; skip them. |
| 318 | """ |
| 319 | # Caller of __array_wrap__ |
| 320 | try: |
| 321 | frame = sys._getframe(1) |
| 322 | except AttributeError: # Not CPython |
| 323 | frame = inspect.stack()[1].frame # pragma: nocover |
| 324 | assert frame.f_back is not None |
| 325 | frame = frame.f_back |
| 326 | |
| 327 | while frame.f_globals.get("__name__", "").startswith("numpy."): |
| 328 | name = frame.f_code.co_name |
| 329 | if not name.startswith("_"): |
| 330 | return name |
| 331 | if frame.f_back is None: |
| 332 | return None |
| 333 | frame = frame.f_back |
| 334 | return None |
| 335 | |
| 336 | |
| 337 | class FrameBase(DaskMethodsMixin): |
no test coverage detected