code: def test_csv_to_libffm():
      df_feature = pd.DataFrame(
          {
              "rating": [1, 0, 0, 1, 1],
              "field1": ["xxx1", "xxx2", "xxx4", "xxx4", "xxx4"],
              "field2": [3, 4, 5, 6, 7],
              "field3": [1.0, 2.0, 3.0, 4.0, 5.0],
              "field4": ["1", "2", "3", "4", "5"],
          }
      )
  
      with TemporaryDirectory() as td:
          filepath = os.path.join(td, "test")
  
          converter = LibffmConverter(filepath=filepath).fit(df_feature)
          df_feature_libffm = converter.transform(df_feature)
  
          # Check the input column types. For example, a bool type is not allowed.
          df_feature_wrong_type = df_feature.copy()
          df_feature_wrong_type["field4"] = True
          with pytest.raises(TypeError) as e:
              LibffmConverter().fit(df_feature_wrong_type)
              assert (
                  e.value
                  == "Input columns should be only object and/or numeric types."
              )
  
          # Check if the dim is the same.
          assert df_feature_libffm.shape == df_feature.shape
  
          # Check if the columns are converted successfully.
          assert df_feature_libffm.iloc[0, :].values.tolist() == [
              1,
              "1:1:1",
              "2:4:3",
              "3:5:1.0",
              "4:6:1",
          ]
  
          # Check if the duplicated column entries are indexed correctly.
          # It should skip counting the duplicated features in a field column.
          assert df_feature_libffm.iloc[-1, :].values.tolist() == [
              1,
              "1:3:1",
              "2:4:7",
              "3:5:5.0",
              "4:10:1",
          ]
  
          # Check if the file is written successfully.
          assert os.path.isfile(filepath)
  
          with open(filepath, "r") as f:
              line = f.readline()
              assert line == "1 1:1:1 2:4:3 3:5:1.0 4:6:1\n"
  
          # Parameters in the transformation should be reported correctly.
          params = converter.get_params()
          assert params == {
              "field count": 4,
              "feature count": 10,
              "file path": filepath,
          }
  
          # Dataset with the same columns should be transformable with a fitted converter.
          df_feature_new = pd.DataFrame(
              {
                  "rating": [1, 0, 0, 1, 1, 1],
                  "field1": [
                      "xxx1",
                      "xxx2",
                      "xxx4",
                      "xxx4",
                      "xxx4",
                      "xxx3",
                  ],
                  "field2": [3, 4, 5, 6, 7, 8],
                  "field3": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
                  "field4": ["1", "2", "3", "4", "5", "6"],
              }
          )
          df_feature_new_libffm = converter.transform(df_feature_new)
  
          assert df_feature_new_libffm.iloc[0, :].values.tolist() == [
              1,
              "1:1:1",
              "2:5:3",
              "3:6:1.0",
              "4:7:1",
          ]
          assert df_feature_new_libffm.iloc[-1, :].values.tolist() == [
              1,
              "1:4:1",
              "2:5:8",
              "3:6:6.0",
              "4:12:1",
          ]
  
file_path: recommenders/tests/unit/recommenders/datasets/test_pandas_df_utils.py
imports: import os
  import numpy
  import pandas
  import pytest
  from tempfile import TemporaryDirectory
  from recommenders.datasets.pandas_df_utils import filter_by, LibffmConverter, has_same_base_dtype, has_columns, lru_cache_df, negative_feedback_sampler
label_desc: Use image node_id 4 for calling a global function with example usage: test_csv_to_libffm() without return types