Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pm4py/util/pandas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def to_dict_records(df):
if is_polars_lazyframe(df):
return df.collect().to_dicts()

return df.to_dict("records")
return df.to_dict(orient="records")


def to_dict_index(df):
Expand All @@ -84,7 +84,7 @@ def to_dict_index(df):
for idx, row in enumerate(collected_df.iter_rows(named=True))
}

return df.to_dict("index")
return df.to_dict(orient="index")


def insert_index(
Expand Down
33 changes: 33 additions & 0 deletions tests/pandas_utils_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest

import pandas as pd

from pm4py.util import pandas_utils


class PandasUtilsTest(unittest.TestCase):
def test_to_dict_uses_keyword_only_orient(self):
"""Tests that pandas to_dict is called with a keyword-only orient."""

class KeywordOnlyDataFrame:
def to_dict(self, *, orient):
return orient

dataframe = KeywordOnlyDataFrame()

self.assertEqual(pandas_utils.to_dict_records(dataframe), "records")
self.assertEqual(pandas_utils.to_dict_index(dataframe), "index")

dataframe = pd.DataFrame([{"case": "A", "event": "start"}])
self.assertEqual(
pandas_utils.to_dict_records(dataframe),
[{"case": "A", "event": "start"}],
)
self.assertEqual(
pandas_utils.to_dict_index(dataframe),
{0: {"case": "A", "event": "start"}},
)


if __name__ == "__main__":
unittest.main()