def _assertPandasAlmostEqual(actual, expected): # Points are unhashable, so pandas' assert_frame_equal can't check they're the same by default. # We need to convert them to something that can be checked. def convert_points(pt): if any(isinstance(pt, t) for t in [PythonOnlyPoint, ExamplePoint]): return pt.x, pt.y return pt assertPandasAlmostEqual(actual, expected, convert=convert_points)
def _assertPandasAlmostEqual(actual, expected): # Points are unhashable, so pandas' assert_frame_equal can't check they're the same by default. # We need to convert them to something that can be checked. def convert_points(pt): if any(isinstance(pt, t) for t in [PythonOnlyPoint, ExamplePoint]): return (pt.x, pt.y) return pt assertPandasAlmostEqual(actual, expected, convert=convert_points)
def _assertPandasAlmostEqual(actual, expected, sortby): def convert_estimators(x): # note convertion makes estimators invariant to training order. if isinstance(x, SparkSklearnEstimator): x = x.estimator if isinstance(x, LinearRegression) or isinstance(x, LogisticRegression): return x.coef_, x.intercept_ if isinstance(x, PCA): return _sortByComponentWeight(x) return x assertPandasAlmostEqual(actual, expected, convert=convert_estimators, sortby=sortby)
def _assertPandasAlmostEqual(actual, expected, sortby): def convert_estimators( x ): # note convertion makes estimators invariant to training order. if isinstance(x, SparkSklearnEstimator): x = x.estimator if isinstance(x, LinearRegression) or isinstance( x, LogisticRegression): return x.coef_, x.intercept_ if isinstance(x, PCA): return _sortByComponentWeight(x) return x assertPandasAlmostEqual(actual, expected, convert=convert_estimators, sortby=sortby)