{"record":{"id":"d1ecc0528735166c","repo":"pola-rs/polars","slug":"pyarrow-is-required-for-converting-a-pandas-series","errorCode":null,"errorMessage":"pyarrow is required for converting a pandas series to Polars, unless it is a simple numpy-backed one (e.g. 'int64', 'bool', 'float32' - not 'Int64')","messagePattern":"pyarrow is required for converting a pandas series to Polars, unless it is a simple numpy-backed one \\(e\\.g\\. 'int64', 'bool', 'float32' - not 'Int64'\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/construction/series.py","lineNumber":438,"sourceCode":"    dtype: PolarsDataType | None = None,\n    *,\n    strict: bool = True,\n    nan_to_null: bool = True,\n) -> PySeries:\n    \"\"\"Construct a PySeries from a pandas Series or DatetimeIndex.\"\"\"\n    if not name and values.name is not None:\n        name = str(values.name)\n    if is_simple_numpy_backed_pandas_series(values):\n        return pl.Series(\n            name, values.to_numpy(), dtype=dtype, nan_to_null=nan_to_null, strict=strict\n        )._s\n    if not _PYARROW_AVAILABLE:\n        msg = (\n            \"pyarrow is required for converting a pandas series to Polars, \"\n            \"unless it is a simple numpy-backed one \"\n            \"(e.g. 'int64', 'bool', 'float32' - not 'Int64')\"\n        )\n        raise ImportError(msg)\n    return arrow_to_pyseries(\n        name,\n        plc.pandas_series_to_arrow(values, nan_to_null=nan_to_null),\n        dtype=dtype,\n        strict=strict,\n    )\n\n\ndef arrow_to_pyseries(\n    name: str,\n    values: pa.Array,\n    dtype: PolarsDataType | None = None,\n    *,\n    strict: bool = True,\n    rechunk: bool = True,\n) -> PySeries:\n    \"\"\"Construct a PySeries from an Arrow array.\"\"\"\n    array = plc.coerce_arrow(values)","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/construction/series.py#L420-L456","documentation":"pandas_to_pyseries has a fast path only for simple NumPy-backed pandas dtypes (plain int/bool/float, or object-of-str without NaN). Everything else — nullable 'Int64', 'string[python]', categorical, tz-aware datetimes — is routed through pyarrow; if pyarrow is not installed, polars raises this ImportError rather than producing wrong data.","triggerScenarios":"pl.from_pandas(pd.Series([1, 2], dtype=\"Int64\")) with no pyarrow in the environment; converting pd.Series of pd.Timestamp or category dtype; pl.Series(pandas_series) with nullable dtypes.","commonSituations":"Slim deployment images (lambda, distroless) that omit pyarrow; dependency resolvers uninstalling pyarrow during a downgrade; notebooks where pyarrow was pip-removed to save space.","solutions":["Install pyarrow: pip install pyarrow (or polars[pyarrow] extras where offered).","Convert to a plain NumPy dtype at the boundary: s.astype(\"int64\") / s.to_numpy() and wrap with pl.Series(...).","Avoid pandas nullable/extension dtypes (Int64, string, boolean) when pyarrow is unavailable."],"exampleFix":"// before\nps = pd.Series([1, 2], dtype=\"Int64\")\ns = pl.Series(ps)  # ImportError without pyarrow\n\n// after\ns = pl.Series(ps.to_numpy())  # or: pip install pyarrow","handlingStrategy":"validation","validationCode":"import importlib.util\n\nneeds_arrow = str(ps.dtype) not in {\"int64\", \"int32\", \"float64\", \"float32\", \"bool\", \"object\"}\nif needs_arrow and importlib.util.find_spec(\"pyarrow\") is None:\n    ps = ps.astype(\"int64\") if \"Int\" in str(ps.dtype) else ps  # or raise with a clear message\ns = pl.Series(ps)","typeGuard":"def is_simple_numpy_backed(ps: pd.Series) -> bool:\n    return str(ps.dtype) in {\"int64\", \"int32\", \"float64\", \"float32\", \"bool\"} or (\n        ps.dtype == \"object\" and not ps.hasnans and len(ps) and isinstance(ps.iloc[0], str)\n    )","tryCatchPattern":"try:\n    s = pl.Series(ps)\nexcept ImportError as e:\n    if \"pyarrow is required\" in str(e):\n        s = pl.Series(ps.to_numpy())  # nullable metadata is lost; decide knowingly\n    else:\n        raise","preventionTips":["Add pyarrow to the deployment image next to pandas+polars.","Convert pandas nullable/extension dtypes to numpy dtypes at the boundary.","Fail fast at startup: import pyarrow in your package's pandas-interop module."],"tags":["pandas","pyarrow","importerror","environment"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}