From 0dda99bbb080d5cf8a6ecc350d0a789e7fa56549 Mon Sep 17 00:00:00 2001 From: Guilhem de Viry Date: Wed, 14 Jun 2023 18:39:04 +0200 Subject: [PATCH] fix(python): match Field signatures (#1463) # Description Field signatures are not identical on the `type` field, which makes instantiating deltalake Fields with the `type` keyword impossible in python - and the `name` keyword as well for that matter. # Related Issue(s) # Documentation --- python/src/schema.rs | 8 ++++---- python/tests/test_schema.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/python/src/schema.rs b/python/src/schema.rs index 1c6f93a764..1e1a75c387 100644 --- a/python/src/schema.rs +++ b/python/src/schema.rs @@ -599,7 +599,7 @@ impl MapType { /// Field("my_col", PrimitiveType("integer"), nullable=True, metadata={"custom_metadata": {"test": 2}}) #[pyclass( module = "deltalake.schema", - text_signature = "(name, ty, nullable=True, metadata=None)" + text_signature = "(name, type, nullable=True, metadata=None)" )] #[derive(Clone)] pub struct Field { @@ -609,15 +609,15 @@ pub struct Field { #[pymethods] impl Field { #[new] - #[pyo3(signature = (name, ty, nullable = true, metadata = None))] + #[pyo3(signature = (name, r#type, nullable = true, metadata = None))] fn new( name: String, - ty: PyObject, + r#type: PyObject, nullable: bool, metadata: Option, py: Python, ) -> PyResult { - let ty = python_type_to_schema(ty, py)?; + let ty = python_type_to_schema(r#type, py)?; // Serialize and de-serialize JSON (it needs to be valid JSON anyways) let metadata: HashMap = if let Some(ref json) = metadata { diff --git a/python/tests/test_schema.py b/python/tests/test_schema.py index b65fa0d9cc..0a7f3d636d 100644 --- a/python/tests/test_schema.py +++ b/python/tests/test_schema.py @@ -170,7 +170,7 @@ def test_delta_field(): # TODO: are there field names we should reject? for name, ty, nullable, metadata in args: - field = Field(name, ty, nullable=nullable, metadata=metadata) + field = Field(name=name, type=ty, nullable=nullable, metadata=metadata) assert field.name == name assert field.type == (PrimitiveType(ty) if isinstance(ty, str) else ty)