code: def _timedelta_to_pl_duration(
      td: timedelta | str | None,
  ) -> str | None:
      """Convert python timedelta to a polars duration string."""
      if td is None or isinstance(td, str):
          return td
  
      if td.days >= 0:
          d = td.days and f"{td.days}d" or ""
          s = td.seconds and f"{td.seconds}s" or ""
          us = td.microseconds and f"{td.microseconds}us" or ""
      else:
          if not td.seconds and not td.microseconds:
              d = td.days and f"{td.days}d" or ""
              s = ""
              us = ""
          else:
              corrected_d = td.days + 1
              d = corrected_d and f"{corrected_d}d" or "-"
              corrected_seconds = SECONDS_PER_DAY - (
                  td.seconds + (td.microseconds > 0)
              )
              s = corrected_seconds and f"{corrected_seconds}s" or ""
              us = (
                  td.microseconds
                  and f"{10**6 - td.microseconds}us"
                  or ""
              )
  
      return f"{d}{s}{us}"
  
imports: from __future__ import annotations
  import sys
  from datetime import datetime, time, timedelta, timezone
  from decimal import Context
  from functools import lru_cache
  from typing import TYPE_CHECKING, Any, Callable, Sequence, TypeVar, overload
  from polars.dependencies import _ZONEINFO_AVAILABLE, zoneinfo
label_desc: Use image node_id 4 for calling a global function with example usage: _timedelta_to_pl_duration(td) and returns: d, s, us, td