# Path: sksurv/base.py
# class SurvivalAnalysisMixin:
# 
#     def score(self, X, y):
#         """Returns the concordance index of the prediction.
# 
#         Parameters
#         ----------
#         X : array-like, shape = (n_samples, n_features)
#             Test samples.
# 
#         y : structured array, shape = (n_samples,)
#             A structured array containing the binary event indicator
#             as first field, and time of event or time of censoring as
#             second field.
# 
#         Returns
#         -------
#         cindex : float
#             Estimated concordance index.
#         """
#         from .metrics import concordance_index_censored
#         name_event, name_time = y.dtype.names
# 
#         risk_score = self.predict(X)
#         if not getattr(self, "_predict_risk_score", True):
#             risk_score *= -1  # convert prediction on time scale to risk scale
# 
#         result = concordance_index_censored(y[name_event], y[name_time], risk_score)
#         return result[0]
# 
# Path: sksurv/datasets/base.py
# def load_whas500():
#     """Load and return the Worcester Heart Attack Study dataset
# 
#     The dataset has 500 samples and 14 features.
#     The endpoint is death, which occurred for 215 patients (43.0%).
# 
#     See [1]_, [2]_ for further description.
# 
#     Returns
#     -------
#     x : pandas.DataFrame
#         The measurements for each patient.
# 
#     y : structured array with 2 fields
#         *fstat*: boolean indicating whether the endpoint has been reached
#         or the event time is right censored.
# 
#         *lenfol*: total length of follow-up (days from hospital admission date
#         to date of last follow-up)
# 
#     References
#     ----------
#     .. [1] https://web.archive.org/web/20170114043458/http://www.umass.edu/statdata/statdata/data/
# 
#     .. [2] Hosmer, D., Lemeshow, S., May, S.:
#         "Applied Survival Analysis: Regression Modeling of Time to Event Data."
#         John Wiley & Sons, Inc. (2008)
#     """
#     fn = resource_filename(__name__, 'data/whas500.arff')
#     return get_x_y(loadarff(fn), attr_labels=['fstat', 'lenfol'], pos_label='1')


from importlib import import_module
from os.path import dirname
from numpy.testing import assert_array_equal
from sksurv.base import SurvivalAnalysisMixin
from sksurv.datasets import load_whas500
import inspect
import pkgutil
import numpy
import pandas
import pytest
import sksurv




def is_survival_mixin(x):
    return inspect.isclass(x) and x is not SurvivalAnalysisMixin and issubclass(x, SurvivalAnalysisMixin)


def all_survival_estimators():
    root = dirname(sksurv.__file__)
    all_classes = []
    for _importer, modname, _ispkg in pkgutil.walk_packages(path=[root], prefix="sksurv."):
        # meta-estimators require base estimators
        if modname.startswith("sksurv.meta"):
            continue
        module = import_module(modname)
        for _name, cls in inspect.getmembers(module, is_survival_mixin):
            if inspect.isabstract(cls):
                continue
            all_classes.append(cls)
    return set(all_classes)


@pytest.mark.parametrize("estimator_cls", all_survival_estimators())
def test_pandas_inputs(estimator_cls):

# Path: sksurv/base.py
# class SurvivalAnalysisMixin:
# 
#     def score(self, X, y):
#         """Returns the concordance index of the prediction.
# 
#         Parameters
#         ----------
#         X : array-like, shape = (n_samples, n_features)
#             Test samples.
# 
#         y : structured array, shape = (n_samples,)
#             A structured array containing the binary event indicator
#             as first field, and time of event or time of censoring as
#             second field.
# 
#         Returns
#         -------
#         cindex : float
#             Estimated concordance index.
#         """
#         from .metrics import concordance_index_censored
#         name_event, name_time = y.dtype.names
# 
#         risk_score = self.predict(X)
#         if not getattr(self, "_predict_risk_score", True):
#             risk_score *= -1  # convert prediction on time scale to risk scale
# 
#         result = concordance_index_censored(y[name_event], y[name_time], risk_score)
#         return result[0]
# 
# Path: sksurv/datasets/base.py
# def load_whas500():
#     """Load and return the Worcester Heart Attack Study dataset
# 
#     The dataset has 500 samples and 14 features.
#     The endpoint is death, which occurred for 215 patients (43.0%).
# 
#     See [1]_, [2]_ for further description.
# 
#     Returns
#     -------
#     x : pandas.DataFrame
#         The measurements for each patient.
# 
#     y : structured array with 2 fields
#         *fstat*: boolean indicating whether the endpoint has been reached
#         or the event time is right censored.
# 
#         *lenfol*: total length of follow-up (days from hospital admission date
#         to date of last follow-up)
# 
#     References
#     ----------
#     .. [1] https://web.archive.org/web/20170114043458/http://www.umass.edu/statdata/statdata/data/
# 
#     .. [2] Hosmer, D., Lemeshow, S., May, S.:
#         "Applied Survival Analysis: Regression Modeling of Time to Event Data."
#         John Wiley & Sons, Inc. (2008)
#     """
#     fn = resource_filename(__name__, 'data/whas500.arff')
#     return get_x_y(loadarff(fn), attr_labels=['fstat', 'lenfol'], pos_label='1')


# Path: tests/test_pandas_inputs.py
from importlib import import_module
from os.path import dirname
from numpy.testing import assert_array_equal
from sksurv.base import SurvivalAnalysisMixin
from sksurv.datasets import load_whas500
import inspect
import pkgutil
import numpy
import pandas
import pytest
import sksurv





def is_survival_mixin(x):
    return inspect.isclass(x) and x is not SurvivalAnalysisMixin and issubclass(x, SurvivalAnalysisMixin)


def all_survival_estimators():
    root = dirname(sksurv.__file__)
    all_classes = []
    for _importer, modname, _ispkg in pkgutil.walk_packages(path=[root], prefix="sksurv."):
        # meta-estimators require base estimators
        if modname.startswith("sksurv.meta"):
            continue
        module = import_module(modname)
        for _name, cls in inspect.getmembers(module, is_survival_mixin):
            if inspect.isabstract(cls):
                continue
            all_classes.append(cls)
    return set(all_classes)


@pytest.mark.parametrize("estimator_cls", all_survival_estimators())
def test_pandas_inputs(estimator_cls):

    X, y = load_whas500()