code: def numpy_to_pydf(
      data: np.ndarray[Any, Any],
      schema: SchemaDefinition | None = None,
      *,
      schema_overrides: SchemaDict | None = None,
      orient: Orientation | None = None,
      nan_to_null: bool = False,
  ) -> PyDataFrame:
      """Construct a PyDataFrame from a numpy ndarray (including structured ndarrays)."""
      shape = data.shape
      two_d = len(shape) == 2
  
      if data.dtype.names is not None:
          structured_array, orient = True, "col"
          record_names = list(data.dtype.names)
          n_columns = len(record_names)
          for nm in record_names:
              shape = data[nm].shape
              if len(data[nm].shape) > 2:
                  raise ValueError(
                      f"cannot create DataFrame from structured array with elements > 2D; shape[{nm!r}] = {shape}"
                  )
          if not schema:
              schema = record_names
      else:
          # Unpack columns
          structured_array, record_names = False, []
          if shape == (0,):
              n_columns = 0
  
          elif len(shape) == 1:
              n_columns = 1
  
          elif len(shape) == 2:
              if orient is None and schema is None:
                  # default convention; first axis is rows, second axis is columns
                  n_columns = shape[1]
                  orient = "row"
  
              elif orient is None and schema is not None:
                  # infer orientation from 'schema' param; if square array
                  # we check the flags to establish row/column major order
                  n_schema_cols = len(schema)
                  if (
                      n_schema_cols == shape[0]
                      and n_schema_cols != shape[1]
                  ):
                      orient = "col"
                      n_columns = shape[0]
                  elif (
                      data.flags["F_CONTIGUOUS"]
                      and shape[0] == shape[1]
                  ):
                      orient = "col"
                      n_columns = n_schema_cols
                  else:
                      orient = "row"
                      n_columns = shape[1]
  
              elif orient == "row":
                  n_columns = shape[1]
              elif orient == "col":
                  n_columns = shape[0]
              else:
                  raise ValueError(
                      f"`orient` must be one of {{'col', 'row', None}}, got {orient!r}"
                  )
          else:
              raise ValueError(
                  f"cannot create DataFrame from array with more than two dimensions; shape = {shape}"
              )
  
      if schema is not None and len(schema) != n_columns:
          if (n_schema_cols := len(schema)) != 1:
              raise ValueError(
                  f"dimensions of `schema` ({n_schema_cols}) must match data dimensions ({n_columns})"
              )
          n_columns = n_schema_cols
  
      column_names, schema_overrides = _unpack_schema(
          schema,
          schema_overrides=schema_overrides,
          n_expected=n_columns,
      )
  
      # Convert data to series
      if structured_array:
          data_series = [
              pl.Series(
                  name=series_name,
                  values=data[record_name],
                  dtype=schema_overrides.get(record_name),
                  nan_to_null=nan_to_null,
              )._s
              for series_name, record_name in zip(
                  column_names, record_names
              )
          ]
      elif shape == (0,):
          data_series = []
  
      elif len(shape) == 1:
          data_series = [
              pl.Series(
                  name=column_names[0],
                  values=data,
                  dtype=schema_overrides.get(column_names[0]),
                  nan_to_null=nan_to_null,
              )._s
          ]
      else:
          if orient == "row":
              data_series = [
                  pl.Series(
                      name=column_names[i],
                      values=(
                          data
                          if two_d and n_columns == 1 and shape[1] > 1
                          else data[:, i]
                      ),
                      dtype=schema_overrides.get(column_names[i]),
                      nan_to_null=nan_to_null,
                  )._s
                  for i in range(n_columns)
              ]
          else:
              data_series = [
                  pl.Series(
                      name=column_names[i],
                      values=(
                          data
                          if two_d and n_columns == 1 and shape[1] > 1
                          else data[i]
                      ),
                      dtype=schema_overrides.get(column_names[i]),
                      nan_to_null=nan_to_null,
                  )._s
                  for i in range(n_columns)
              ]
  
      data_series = _handle_columns_arg(
          data_series, columns=column_names
      )
      return PyDataFrame(data_series)
  
imports: from __future__ import annotations
  import contextlib
  import warnings
  from datetime import date, datetime, time, timedelta
  from decimal import Decimal
  from functools import lru_cache, singledispatch
  from itertools import islice, zip_longest
  from operator import itemgetter
  from sys import version_info
  from typing import TYPE_CHECKING, Any, Callable, Generator, Iterable, Iterator, Mapping, MutableMapping, Sequence, get_type_hints
  import polars._reexport
  from polars import functions
  from polars.datatypes import INTEGER_DTYPES, N_INFER_DEFAULT, TEMPORAL_DTYPES, Boolean, Categorical, Date, Datetime, Duration, Enum, List, Null, Object, String, Struct, Time, UInt32, Unknown, dtype_to_py_type, is_polars_dtype, numpy_char_code_to_dtype, py_type_to_dtype
  from polars.datatypes.constructor import numpy_type_to_constructor, numpy_values_and_dtype, polars_type_to_constructor, py_type_to_constructor
  from polars.dependencies import _NUMPY_AVAILABLE, _check_for_numpy, _check_for_pandas, _check_for_pydantic, dataclasses, pydantic
  from polars.dependencies import numpy
  from polars.dependencies import pandas
  from polars.dependencies import pyarrow
  from polars.exceptions import ComputeError, ShapeError, TimeZoneAwareConstructorWarning
  from polars.utils._wrap import wrap_df, wrap_s
  from polars.utils.meta import get_index_type, threadpool_size
  from polars.utils.various import _is_generator, arrlen, find_stacklevel, parse_version, range_to_series
label_desc: Use image node_id 36 for calling a global function with example usage: numpy_to_pydf(data, schema) and returns: PyDataFrame