code: def compute_string_statistics(
      df: pl.dataframe.frame.DataFrame,
      column_name: str,
      n_bins: int,
      n_samples: int,
      dtype: Optional[str],
  ) -> Union[CategoricalStatisticsItem, NumericalStatisticsItem]:
      if dtype != "large_string":
          n_unique = df[column_name].n_unique()
          nan_count = df[column_name].null_count()
          nan_proportion = (
              np.round(nan_count / n_samples, DECIMALS).item()
              if nan_count != 0
              else 0.0
          )
  
          if n_unique <= MAX_NUM_STRING_LABELS:
              labels2counts: dict[str, int] = dict(df[column_name].value_counts().rows())  # type: ignore
              logging.debug(
                  f"{n_unique=} {nan_count=} {nan_proportion=} {labels2counts=}"
              )
              # exclude counts of None values from frequencies if exist:
              labels2counts.pop(None, None)  # type: ignore
              return CategoricalStatisticsItem(
                  nan_count=nan_count,
                  nan_proportion=nan_proportion,
                  no_label_count=0,
                  no_label_proportion=0.0,
                  n_unique=len(labels2counts),
                  frequencies=labels2counts,
              )
  
      lengths_df = df.select(pl.col(column_name)).with_columns(
          pl.col(column_name)
          .str.len_chars()
          .alias(f"{column_name}_len")
      )
      return compute_numerical_statistics(
          df=lengths_df,
          column_name=f"{column_name}_len",
          n_bins=n_bins,
          n_samples=n_samples,
          column_type=ColumnType.INT,
      )
  
imports: import enum
  import logging
  import os
  from pathlib import Path
  from typing import Any, Optional, TypedDict, Union
  import numpy
  import polars
  from datasets import ClassLabel, Features
  from huggingface_hub import hf_hub_download
  from libcommon.exceptions import CacheDirectoryNotInitializedError, NoSupportedFeaturesError, ParquetResponseEmptyError, PreviousStepFormatError, SplitWithTooBigParquetError, StatisticsComputationError
  from libcommon.simple_cache import get_previous_step_or_raise
  from libcommon.storage import StrPath
  from libcommon.utils import JobInfo
  from requests.exceptions import ReadTimeout
  from tqdm import tqdm
  from worker.config import AppConfig, DescriptiveStatisticsConfig
  from worker.dtos import CompleteJobResult
  from worker.job_runners.split.split_job_runner import SplitJobRunnerWithCache
  from worker.utils import HF_HUB_HTTP_ERROR_RETRY_SLEEPS, retry
label_desc: Use image node_id 6 for calling a global function with example usage: compute_string_statistics(df, column_name, n_bins, n_samples, dtype) and returns: compute_numerical_statistics, CategoricalStatisticsItem