diff --git a/py-polars/polars/dataframe/frame.py b/py-polars/polars/dataframe/frame.py index cd59cc6bcdf7..79ea711ff14c 100644 --- a/py-polars/polars/dataframe/frame.py +++ b/py-polars/polars/dataframe/frame.py @@ -390,20 +390,6 @@ def __init__( nan_to_null=nan_to_null, ) - elif hasattr(data, "__arrow_c_array__"): - # This uses the fact that PySeries.from_arrow_c_array will create a - # struct-typed Series. Then we unpack that to a DataFrame. - tmp_col_name = "" - s = wrap_s(PySeries.from_arrow_c_array(data)) - self._df = s.to_frame(tmp_col_name).unnest(tmp_col_name)._df - - elif hasattr(data, "__arrow_c_stream__"): - # This uses the fact that PySeries.from_arrow_c_stream will create a - # struct-typed Series. Then we unpack that to a DataFrame. - tmp_col_name = "" - s = wrap_s(PySeries.from_arrow_c_stream(data)) - self._df = s.to_frame(tmp_col_name).unnest(tmp_col_name)._df - elif _check_for_pyarrow(data) and isinstance(data, pa.Table): self._df = arrow_to_pydf( data, schema=schema, schema_overrides=schema_overrides, strict=strict @@ -428,6 +414,21 @@ def __init__( self._df = dataframe_to_pydf( data, schema=schema, schema_overrides=schema_overrides, strict=strict ) + + elif hasattr(data, "__arrow_c_array__"): + # This uses the fact that PySeries.from_arrow_c_array will create a + # struct-typed Series. Then we unpack that to a DataFrame. + tmp_col_name = "" + s = wrap_s(PySeries.from_arrow_c_array(data)) + self._df = s.to_frame(tmp_col_name).unnest(tmp_col_name)._df + + elif hasattr(data, "__arrow_c_stream__"): + # This uses the fact that PySeries.from_arrow_c_stream will create a + # struct-typed Series. Then we unpack that to a DataFrame. + tmp_col_name = "" + s = wrap_s(PySeries.from_arrow_c_stream(data)) + self._df = s.to_frame(tmp_col_name).unnest(tmp_col_name)._df + else: msg = ( f"DataFrame constructor called with unsupported type {type(data).__name__!r}" diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index 9a2badc28a86..42eaee869031 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -318,12 +318,6 @@ def __init__( if dtype is not None: self._s = self.cast(dtype, strict=strict)._s - elif hasattr(values, "__arrow_c_array__"): - self._s = PySeries.from_arrow_c_array(values) - - elif hasattr(values, "__arrow_c_stream__"): - self._s = PySeries.from_arrow_c_stream(values) - elif _check_for_pyarrow(values) and isinstance( values, (pa.Array, pa.ChunkedArray) ): @@ -347,6 +341,12 @@ def __init__( original_name, values, dtype=dtype, strict=strict ) + elif hasattr(values, "__arrow_c_array__"): + self._s = PySeries.from_arrow_c_array(values) + + elif hasattr(values, "__arrow_c_stream__"): + self._s = PySeries.from_arrow_c_stream(values) + else: msg = ( f"Series constructor called with unsupported type {type(values).__name__!r}"