Repository: facultyai/marshmallow-dataframe

Issue:
Should index be mandatory on split format?
Hi, and thanks for the work on this package ! 
I am also trying to get that working nicely together...

I recently encountered : 
```
{'index': ['Missing data for required field.']}
```
But I expected index to be optional (when not present assume range(n), same as pandas.DataFrame()

What do you think ?


Discussion:

Patch:
diff --git a/src/marshmallow_dataframe/split.py b/src/marshmallow_dataframe/split.py
index b988e67..9fc4db4 100644
--- a/src/marshmallow_dataframe/split.py
+++ b/src/marshmallow_dataframe/split.py
@@ -31,7 +31,11 @@ class SplitDataFrameSchemaMeta(DataFrameSchemaMeta):
                 else dtype_to_field(index_dtype)
             )
 
-            fields["index"] = ma.fields.List(index_field, required=True)
+            index_required = False if index_dtype is None else True
+
+            fields["index"] = ma.fields.List(
+                index_field, required=index_required
+            )
 
             fields["columns"] = ma.fields.List(
                 ma.fields.String,
@@ -51,7 +55,9 @@ class SplitDataFrameSchema(ma.Schema, metaclass=SplitDataFrameSchemaMeta):
 
     @ma.validates_schema(skip_on_field_errors=True)
     def validate_index_data_length(self, data: dict, **kwargs) -> None:
-        if len(data["index"]) != len(data["data"]):
+        if data.get("index") is not None and len(data["index"]) != len(
+            data["data"]
+        ):
             raise ma.ValidationError(
                 "Length of `index` and `data` must be equal.", "data"
             )


Test patch:
diff --git a/tests/test_split.py b/tests/test_split.py
index ba2154f..ac975d4 100644
--- a/tests/test_split.py
+++ b/tests/test_split.py
@@ -114,6 +114,23 @@ def test_split_schema_missing_top_level_key(
     assert exc.value.messages[key] == ["Missing data for required field."]
 
 
+@pytest.mark.parametrize("require_index", [True, False])
+def test_optional_index_field(sample_df, require_index):
+    class MySchema(SplitDataFrameSchema):
+        class Meta:
+            dtypes = sample_df.dtypes
+            index_dtype = sample_df.index.dtype if require_index else None
+
+    serialized_df = serialize_df(sample_df, orient="split")
+
+    if not require_index:
+        del serialized_df["index"]
+
+    output = MySchema().load(serialized_df)
+
+    assert_frame_equal(output, sample_df)
+
+
 def test_split_schema_str_index(sample_df):
     test_df = sample_df.copy()
     test_df.index = test_df.index.astype(str)