Skip to content

[python] DataFrame with datetime index support #4057

Description

@tchan09

Search before asking

  • I had searched in the issues and found no similar issues.

Version

pyfory 1.7.3
python 3.13

Component(s)

Python

Minimal reproduce step

With pyfory 1.7.3, it doesn't look like DataFrames with a datetime index (or any datetime dtype column) are supported.

Test case:

import pytest
import pyfory
import pandas as pd
import numpy as np

@pytest.fixture(scope="session")
def fory() -> pyfory.Fory:
    fory = pyfory.Fory(xlang=False, ref=False, strict=False, compatible=False)
    return fory

@pytest.fixture(scope="session")
def df() -> pd.DataFrame:
    rng = np.random.default_rng(0)
    index = pd.date_range("2026-01-01", periods=10, freq="D", name="date")
    return pd.DataFrame(
        {
            "a": rng.random(10, dtype=np.float64),
            "b": rng.random(10, dtype=np.float64),
            "c": rng.random(10, dtype=np.float64),
        },
        index=index,
    )

def test_dataframe_fory_with_buffer(fory: pyfory.Fory, df: pd.DataFrame):
    buffers: list[memoryview] = []
    data = fory.dumps(df, buffer_callback=buffers.append)
    buffers = [o.getbuffer() for o in buffers]
    restored = fory.loads(data, buffers=buffers)

    pd.testing.assert_frame_equal(restored, df)

What did you expect to see?

Roundtrip of the dataframe.

What did you see instead?

FAILED test_serialization.py::test_dataframe_fory_with_buffer - ValueError: cannot include dtype 'M' in a buffer

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions