|
21 | 21 | cast, |
22 | 22 | overload, |
23 | 23 | ) |
24 | | -from warnings import warn |
25 | 24 |
|
26 | 25 | from narwhals._enum import NoAutoEnum |
| 26 | +from narwhals._exceptions import issue_deprecation_warning |
27 | 27 | from narwhals._typing_compat import assert_never, deprecated |
28 | 28 | from narwhals.dependencies import ( |
29 | 29 | get_cudf, |
|
46 | 46 | is_polars_series, |
47 | 47 | is_pyarrow_chunked_array, |
48 | 48 | ) |
49 | | -from narwhals.exceptions import ( |
50 | | - ColumnNotFoundError, |
51 | | - DuplicateError, |
52 | | - InvalidOperationError, |
53 | | - PerformanceWarning, |
54 | | -) |
| 49 | +from narwhals.exceptions import ColumnNotFoundError, DuplicateError, InvalidOperationError |
55 | 50 |
|
56 | 51 | if TYPE_CHECKING: |
57 | 52 | from collections.abc import Set # noqa: PYI025 |
@@ -1431,68 +1426,6 @@ def is_sequence_of(obj: Any, tp: type[_T]) -> TypeIs[Sequence[_T]]: |
1431 | 1426 | ) |
1432 | 1427 |
|
1433 | 1428 |
|
1434 | | -def find_stacklevel() -> int: |
1435 | | - """Find the first place in the stack that is not inside narwhals. |
1436 | | -
|
1437 | | - Returns: |
1438 | | - Stacklevel. |
1439 | | -
|
1440 | | - Taken from: |
1441 | | - https://github.com/pandas-dev/pandas/blob/ab89c53f48df67709a533b6a95ce3d911871a0a8/pandas/util/_exceptions.py#L30-L51 |
1442 | | - """ |
1443 | | - import inspect |
1444 | | - from pathlib import Path |
1445 | | - |
1446 | | - import narwhals as nw |
1447 | | - |
1448 | | - pkg_dir = str(Path(nw.__file__).parent) |
1449 | | - |
1450 | | - # https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slow |
1451 | | - frame = inspect.currentframe() |
1452 | | - n = 0 |
1453 | | - try: |
1454 | | - while frame: |
1455 | | - fname = inspect.getfile(frame) |
1456 | | - if fname.startswith(pkg_dir) or ( |
1457 | | - (qualname := getattr(frame.f_code, "co_qualname", None)) |
1458 | | - # ignore @singledispatch wrappers |
1459 | | - and qualname.startswith("singledispatch.") |
1460 | | - ): |
1461 | | - frame = frame.f_back |
1462 | | - n += 1 |
1463 | | - else: # pragma: no cover |
1464 | | - break |
1465 | | - else: # pragma: no cover |
1466 | | - pass |
1467 | | - finally: |
1468 | | - # https://docs.python.org/3/library/inspect.html |
1469 | | - # > Though the cycle detector will catch these, destruction of the frames |
1470 | | - # > (and local variables) can be made deterministic by removing the cycle |
1471 | | - # > in a finally clause. |
1472 | | - del frame |
1473 | | - return n |
1474 | | - |
1475 | | - |
1476 | | -def issue_deprecation_warning(message: str, _version: str) -> None: # pragma: no cover |
1477 | | - """Issue a deprecation warning. |
1478 | | -
|
1479 | | - Arguments: |
1480 | | - message: The message associated with the warning. |
1481 | | - _version: Narwhals version when the warning was introduced. Just used for internal |
1482 | | - bookkeeping. |
1483 | | - """ |
1484 | | - warn(message=message, category=DeprecationWarning, stacklevel=find_stacklevel()) |
1485 | | - |
1486 | | - |
1487 | | -def issue_performance_warning(message: str) -> None: |
1488 | | - """Issue a performance warning. |
1489 | | -
|
1490 | | - Arguments: |
1491 | | - message: The message associated with the warning. |
1492 | | - """ |
1493 | | - warn(message=message, category=PerformanceWarning, stacklevel=find_stacklevel()) |
1494 | | - |
1495 | | - |
1496 | 1429 | def validate_strict_and_pass_though( |
1497 | 1430 | strict: bool | None, # noqa: FBT001 |
1498 | 1431 | pass_through: bool | None, # noqa: FBT001 |
@@ -1727,7 +1660,7 @@ def is_eager_allowed(obj: Implementation) -> TypeIs[EagerAllowedImplementation]: |
1727 | 1660 |
|
1728 | 1661 |
|
1729 | 1662 | def has_native_namespace(obj: Any) -> TypeIs[SupportsNativeNamespace]: |
1730 | | - return hasattr(obj, "__native_namespace__") |
| 1663 | + return _hasattr_static(obj, "__native_namespace__") |
1731 | 1664 |
|
1732 | 1665 |
|
1733 | 1666 | def _supports_dataframe_interchange(obj: Any) -> TypeIs[DataFrameLike]: |
|
0 commit comments