@@ -28,9 +28,36 @@ class NestedDtype(ExtensionDtype):
2828
2929 Parameters
3030 ----------
31- pyarrow_dtype : pyarrow.StructType or pd.ArrowDtype
32- The pyarrow data type to use for the nested type. It must be a struct
33- type where all fields are list types.
31+ pyarrow_dtype : pyarrow.StructType, pd.ArrowDtype, or Mapping[str, pa.DataType]
32+ The pyarrow data type to use for the nested type. It may be provided as
33+ a pyarrow.StructType, a pandas.ArrowDtype, or a mapping of column names to
34+ pyarrow data types (such as a dictionary).
35+
36+ Examples
37+ --------
38+ >>> import pyarrow as pa
39+ >>> from nested_pandas import NestedDtype
40+
41+ From pa.StructType:
42+
43+ >>> dtype = NestedDtype(pa.struct([pa.field("a", pa.list_(pa.int64())),
44+ ... pa.field("b", pa.list_(pa.float64()))]))
45+ >>> dtype
46+ nested<a: [int64], b: [double]>
47+
48+ From pd.ArrowDtype:
49+
50+ >>> import pandas as pd
51+ >>> dtype = NestedDtype(pd.ArrowDtype(pa.struct([pa.field("a", pa.list_(pa.int64())),
52+ ... pa.field("b", pa.list_(pa.float64()))])))
53+ >>> dtype
54+ nested<a: [int64], b: [double]>
55+
56+ From mapping of column names to pyarrow data types:
57+
58+ >>> dtype = NestedDtype({"a": pa.int64(), "b": pa.float64()})
59+ >>> dtype
60+ nested<a: [int64], b: [double]>
3461 """
3562
3663 # ExtensionDtype overrides #
@@ -160,6 +187,15 @@ def __from_arrow__(self, array: pa.Array | pa.ChunkedArray) -> ExtensionArray:
160187 pyarrow_dtype : pa .StructType
161188
162189 def __init__ (self , pyarrow_dtype : pa .DataType ) -> None :
190+ # Allow pd.ArrowDtypes on init
191+ if isinstance (pyarrow_dtype , pd .ArrowDtype ):
192+ pyarrow_dtype = pyarrow_dtype .pyarrow_dtype
193+
194+ # Allow from_columns-style mapping inputs
195+ if isinstance (pyarrow_dtype , Mapping ):
196+ pyarrow_dtype = pa .struct ({col : pa .list_ (pa_type ) for col , pa_type in pyarrow_dtype .items ()})
197+ pyarrow_dtype = cast (pa .StructType , pyarrow_dtype )
198+
163199 self .pyarrow_dtype , self .list_struct_pa_dtype = self ._validate_dtype (pyarrow_dtype )
164200
165201 @property
0 commit comments