# Path: sksurv/io/arffwrite.py
# def writearff(data, filename, relation_name=None, index=True):
#     """Write ARFF file
# 
#     Parameters
#     ----------
#     data : :class:`pandas.DataFrame`
#         DataFrame containing data
# 
#     filename : string or file-like object
#         Path to ARFF file or file-like object. In the latter case,
#         the handle is closed by calling this function.
# 
#     relation_name : string, optional, default: "pandas"
#         Name of relation in ARFF file.
# 
#     index : boolean, optional, default: True
#         Write row names (index)
#     """
#     if isinstance(filename, str):
#         fp = open(filename, 'w')
# 
#         if relation_name is None:
#             relation_name = os.path.basename(filename)
#     else:
#         fp = filename
# 
#         if relation_name is None:
#             relation_name = "pandas"
# 
#     try:
#         data = _write_header(data, fp, relation_name, index)
#         fp.write("\n")
#         _write_data(data, fp)
#     finally:
#         fp.close()


from io import StringIO
from numpy.testing import assert_array_almost_equal, assert_array_equal
from sksurv.io import writearff
import os
import tempfile
import numpy
import pandas
import pandas.testing as tm
import pytest
import sksurv.datasets as sdata
        assert y.shape == (198,)
        assert_structured_array_dtype(y, 'e.tdm', 't.tdm', 51)

    @staticmethod
    def test_load_flchain():
        x, y = sdata.load_flchain()
        assert x.shape == (7874, 9)
        assert y.shape == (7874,)
        assert_structured_array_dtype(y, 'death', 'futime', 2169)


def _make_and_write_data(fp, n_samples, n_features, with_index, with_labels, seed, column_prefix="V"):
    x, event, time = _make_survival_data(n_samples, n_features, seed)

    columns = ["{}{}".format(column_prefix, i) for i in range(n_features)]
    if with_labels:
        columns += ["event", "time"]
        arr = numpy.column_stack((x, event, time))
    else:
        arr = x

    if with_index:
        index = numpy.arange(n_samples, dtype=float)
        numpy.random.RandomState(0).shuffle(index)
    else:
        index = None

    dataset = pandas.DataFrame(arr, index=index, columns=columns)
    dataset.index.name = "index"


# Path: sksurv/io/arffwrite.py
# def writearff(data, filename, relation_name=None, index=True):
#     """Write ARFF file
# 
#     Parameters
#     ----------
#     data : :class:`pandas.DataFrame`
#         DataFrame containing data
# 
#     filename : string or file-like object
#         Path to ARFF file or file-like object. In the latter case,
#         the handle is closed by calling this function.
# 
#     relation_name : string, optional, default: "pandas"
#         Name of relation in ARFF file.
# 
#     index : boolean, optional, default: True
#         Write row names (index)
#     """
#     if isinstance(filename, str):
#         fp = open(filename, 'w')
# 
#         if relation_name is None:
#             relation_name = os.path.basename(filename)
#     else:
#         fp = filename
# 
#         if relation_name is None:
#             relation_name = "pandas"
# 
#     try:
#         data = _write_header(data, fp, relation_name, index)
#         fp.write("\n")
#         _write_data(data, fp)
#     finally:
#         fp.close()


# Path: tests/test_datasets.py
from io import StringIO
from numpy.testing import assert_array_almost_equal, assert_array_equal
from sksurv.io import writearff
import os
import tempfile
import numpy
import pandas
import pandas.testing as tm
import pytest
import sksurv.datasets as sdata

        assert y.shape == (198,)
        assert_structured_array_dtype(y, 'e.tdm', 't.tdm', 51)

    @staticmethod
    def test_load_flchain():
        x, y = sdata.load_flchain()
        assert x.shape == (7874, 9)
        assert y.shape == (7874,)
        assert_structured_array_dtype(y, 'death', 'futime', 2169)


def _make_and_write_data(fp, n_samples, n_features, with_index, with_labels, seed, column_prefix="V"):
    x, event, time = _make_survival_data(n_samples, n_features, seed)

    columns = ["{}{}".format(column_prefix, i) for i in range(n_features)]
    if with_labels:
        columns += ["event", "time"]
        arr = numpy.column_stack((x, event, time))
    else:
        arr = x

    if with_index:
        index = numpy.arange(n_samples, dtype=float)
        numpy.random.RandomState(0).shuffle(index)
    else:
        index = None

    dataset = pandas.DataFrame(arr, index=index, columns=columns)
    dataset.index.name = "index"


    writearff(dataset, fp, index=with_index)