<commit_before>import warnings

import numpy


class QuadratureScheme:
    def __init__(
        self, name, weights, points, degree, source, tol=1.0e-14, comments=None
    ):
        if tol > 1.0e-12:
            warnings.warn(f"{name} ({self.domain}) has low precision ({tol:.3e}).")

        self.test_tolerance = tol
        self.name = name
        self.degree = degree
        self.source = source
        self.comments = [] if comments is None else comments

        # assert weights.shape[0] == points.shape[1], (
        #     f"Shape mismatch for {name}: "
        #     f"weights.shape = {weights.shape}, points.shape = {points.shape}"
        # )

        if weights.dtype == numpy.float64:
            self.weights = weights
        else:
            assert weights.dtype in [numpy.dtype("O"), numpy.int_]
            self.weights = weights.astype(numpy.float64)
            self.weights_symbolic = weights

        if points.dtype == numpy.float64:
            self.points = points
        else:
            assert points.dtype in [numpy.dtype("O"), numpy.int_]
            self.points = points.astype(numpy.float64)
            self.points_symbolic = points

    def savefig(self, filename, *args, **kwargs):
        from matplotlib import pyplot as plt

        self.plot(*args, **kwargs)
        # mpl keeps a hidden background patch that renders bbox_inches ineffective.
        # keep an eye out for https://stackoverflow.com/q/61712551/353337
        plt.savefig(filename, transparent=True, bbox_inches="tight", pad_inches=0)

    def show(self, *args, **kwargs):
        from matplotlib import pyplot as plt

        self.plot(*args, **kwargs)
        plt.show()

    def __str__(self):
        message = f"<quadrature scheme for {self.domain}>"
        message += f"\n  name:                 {self.name}"
        try:
            source = self.source
        except AttributeError:
            source = None

        if source:
            message += f"\n  source:               {source.title}"
            if source.authors:
                authors = ", ".join(source.authors)
                message += f"\n                        {authors}"

            string = []
            try:
                if source.journal:
                    string.append(source.journal)
            except AttributeError:
                pass
            try:
                if source.volume:
                    string.append(f"vol. {source.volume}")
            except AttributeError:
                pass
            try:
                if source.number:
                    string.append(f"no. {source.number}")
            except AttributeError:
                pass
            try:
                if source.pages:
                    string.append(f"pp. {source.pages}")
            except AttributeError:
                pass
            try:
                if source.year:
                    string.append(source.year)
            except AttributeError:
                pass

            if string:
                s = ", ".join(string)
                message += f"\n                        {s}"
            if source.url:
                message += f"\n                        {source.url}"

        message += f"\n  degree:               {self.degree}"
        message += f"\n  test tolerance:       {self.test_tolerance}"
        message += f"\n  num points/weights:   {len(self.weights)}"

        try:<commit_msg>fix test failures<commit_after>import warnings

import numpy


class QuadratureScheme:
    def __init__(
        self, name, weights, points, degree, source, tol=1.0e-14, comments=None
    ):
        if tol > 1.0e-12:
            warnings.warn(f"{name} ({self.domain}) has low precision ({tol:.3e}).")

        self.test_tolerance = tol
        self.name = name
        self.degree = degree
        self.source = source
        self.comments = [] if comments is None else comments

        # assert weights.shape[0] == points.shape[1], (
        #     f"Shape mismatch for {name}: "
        #     f"weights.shape = {weights.shape}, points.shape = {points.shape}"
        # )

        if weights.dtype == numpy.float64:
            self.weights = weights
        else:
            assert weights.dtype in [numpy.dtype("O"), numpy.int_]
            self.weights = weights.astype(numpy.float64)
            self.weights_symbolic = weights

        if points.dtype == numpy.float64:
            self.points = points
        else:
            assert points.dtype in [numpy.dtype("O"), numpy.int_]
            self.points = points.astype(numpy.float64)
            self.points_symbolic = points

    def savefig(self, filename, *args, **kwargs):
        from matplotlib import pyplot as plt

        self.plot(*args, **kwargs)
        # mpl keeps a hidden background patch that renders bbox_inches ineffective.
        # keep an eye out for https://stackoverflow.com/q/61712551/353337
        plt.savefig(filename, transparent=True, bbox_inches="tight", pad_inches=0)

    def show(self, *args, **kwargs):
        from matplotlib import pyplot as plt

        self.plot(*args, **kwargs)
        plt.show()

    def __str__(self):
        message = f"<quadrature scheme for {self.domain}>"
        message += f"\n  name:                 {self.name}"
        try:
            source = self.source
        except AttributeError:
            source = None

        if source:
            message += f"\n  source:               {source.title}"
            if source.authors:
                authors = ", ".join(source.authors)
                message += f"\n                        {authors}"

            string = []
            try:
                if source.journal:
                    string.append(source.journal)
            except AttributeError:
                pass
            try:
                if source.volume:
                    string.append(f"vol. {source.volume}")
            except AttributeError:
                pass
            try:
                if source.number:
                    string.append(f"no. {source.number}")
            except AttributeError:
                pass
            try:
                if source.pages:
                    string.append(f"pp. {source.pages}")
            except AttributeError:
                pass
            try:
                if source.year:
                    string.append(source.year)
            except AttributeError:
                pass

            if string:
                s = ", ".join(string)
                message += f"\n                        {s}"
            if source.url:
                message += f"\n                        {source.url}"

        message += f"\n  degree:               {self.degree}"
        try:
            message += f"\n  test tolerance:       {self.test_tolerance}"
        except AttributeError:
            pass
        message += f"\n  num points/weights:   {len(self.weights)}"

        try:
{'fraction_non_alphanumeric': 0.10364185979559522, 'fraction_numerical': 0.009788397869583992, 'mean_word_length': 1.3851699279093719, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6019244', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1811, 'n_words': 453}