Skip to content

Commit

Permalink
fix(python): match Field signatures (#1463)
Browse files Browse the repository at this point in the history
# 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)
<!---
For example:

- closes #106
--->

# Documentation

<!---
Share links to useful documentation
--->
  • Loading branch information
guilhem-dvr authored Jun 14, 2023
1 parent 9730d59 commit 0dda99b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions python/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<PyObject>,
py: Python,
) -> PyResult<Self> {
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<String, serde_json::Value> = if let Some(ref json) = metadata {
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0dda99b

Please sign in to comment.