Repository: astropenguin/pandas-dataclasses

Issue:
Update specs module

Discussion:

Patch:
diff --git a/pandas_dataclasses/core.py b/pandas_dataclasses/core.py
index 27dc5c5..fb91019 100644
--- a/pandas_dataclasses/core.py
+++ b/pandas_dataclasses/core.py
@@ -52,7 +52,7 @@ def get_data(obj: DataClass) -> Optional[AnyDict]:
     for key, spec in dataspec.specs.of_data.items():
         dataset[spec.name] = astype(
             atleast_1d(getattr(obj, key)),
-            spec.type,
+            spec.dtype,
         )
 
     if len(dataset) == 0:
@@ -69,7 +69,7 @@ def get_index(obj: DataClass) -> Optional[pd.Index]:
     for key, spec in dataspec.specs.of_index.items():
         dataset[spec.name] = astype(
             atleast_1d(getattr(obj, key)),
-            spec.type,
+            spec.dtype,
         )
 
     if len(dataset) == 0:
diff --git a/pandas_dataclasses/specs.py b/pandas_dataclasses/specs.py
index 2063ce2..c522181 100644
--- a/pandas_dataclasses/specs.py
+++ b/pandas_dataclasses/specs.py
@@ -40,7 +40,7 @@ class ArraySpec:
     role: Literal["data", "index"]
     """Role of the array."""
 
-    type: Optional[AnyDType]
+    dtype: Optional[AnyDType]
     """Data type of the array."""
 
     default: Any
@@ -58,7 +58,7 @@ class ScalarSpec:
     """Role of the scalar."""
 
     type: Any
-    """Data type of the scalar."""
+    """Type (hint) of the scalar."""
 
     default: Any
     """Default value of the scalar."""
@@ -100,7 +100,7 @@ class DataSpec:
         """Create a data specification from a dataclass."""
         dataspec = cls()
 
-        for field in fields(eval_fields(dataclass)):
+        for field in fields(eval_types(dataclass)):
             spec = get_spec(field)
 
             if spec is not None:
@@ -111,7 +111,7 @@ class DataSpec:
 
 # runtime functions
 @lru_cache(maxsize=None)
-def eval_fields(dataclass: Type[TDataClass]) -> Type[TDataClass]:
+def eval_types(dataclass: Type[TDataClass]) -> Type[TDataClass]:
     """Evaluate field types of a dataclass."""
     types = get_type_hints(dataclass, include_extras=True)
 
@@ -131,7 +131,7 @@ def get_spec(field: AnyField) -> Optional[AnySpec]:
         return ArraySpec(
             name=name,
             role=role.value,
-            type=get_dtype(field.type),
+            dtype=get_dtype(field.type),
             default=field.default,
         )
 


Test patch:
diff --git a/tests/test_specs.py b/tests/test_specs.py
index 016aaa5..dd12a70 100644
--- a/tests/test_specs.py
+++ b/tests/test_specs.py
@@ -35,7 +35,7 @@ def test_time() -> None:
 
     assert spec.name == "Time in UTC"
     assert spec.role == "index"
-    assert spec.type == np.dtype("M8[ns]")
+    assert spec.dtype == np.dtype("M8[ns]")
     assert spec.default is MISSING
 
 
@@ -44,7 +44,7 @@ def test_temperature() -> None:
 
     assert spec.name == "Temperature (degC)"
     assert spec.role == "data"
-    assert spec.type == np.float64
+    assert spec.dtype == np.float64
     assert spec.default is MISSING
 
 
@@ -53,7 +53,7 @@ def test_humidity() -> None:
 
     assert spec.name == "Humidity (percent)"
     assert spec.role == "data"
-    assert spec.type == np.float64
+    assert spec.dtype == np.float64
     assert spec.default is MISSING
 
 
@@ -62,7 +62,7 @@ def test_wind_speed() -> None:
 
     assert spec.name == "Speed (m/s)"
     assert spec.role == "data"
-    assert spec.type == np.float64
+    assert spec.dtype == np.float64
     assert spec.default is MISSING
 
 
@@ -71,7 +71,7 @@ def test_wind_direction() -> None:
 
     assert spec.name == "Direction (deg)"
     assert spec.role == "data"
-    assert spec.type == np.float64
+    assert spec.dtype == np.float64
     assert spec.default is MISSING