Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Add example for creating a triangle with preexisting ultimates #523

Open
genedan opened this issue May 23, 2024 · 1 comment
Open
Assignees

Comments

@genedan
Copy link
Contributor

genedan commented May 23, 2024

There is some code that is executed early on in the Triangle constructor that handles the situation where the data contain ultimates:

@staticmethod
    def _split_ult(
            data: DataFrame,
            index: list,
            columns: list,
            origin: list,
            development: list
    ):
        """Deal with triangles with ultimate values"""
        ult = None
        if (
            development
            and len(development) == 1
            and data[development[0]].dtype == "<M8[ns]"
        ):
            u = data[data[development[0]] == options.ULT_VAL].copy()
            if len(u) > 0 and len(u) != len(data):
                ult = Triangle(
                    u,
                    origin=origin,
                    development=development,
                    columns=columns,
                    index=index,
                )
                ult.ddims = pd.DatetimeIndex([options.ULT_VAL])
                data = data[data[development[0]] != options.ULT_VAL]
        return data, ult

Is there a sample or anywhere in the documentation where we supply data with ultimates? From the code it's unclear to me how one would do explicitly, since the way ultimate values are detected depend on the the length of a list and the data type of the values, <M8[ns], which is obscure to me, rather than some explicit flag named "ultimate" or something resembling it.

It seems to me this was written to handle triangles that have already been developed via chainladder rather than as a way to allow the user a way to import ultimate data from the beginning. If it's the former case we can add enhance the docstring, but if the latter perhaps we could add an argument to the triangle constructor explicitly marking the existence of ultimate values.

@jbogaardt
Copy link
Collaborator

I think this was added in the spirit of allowing any triangle that is exported to_frame to be reconstructed back into the same triangle using the constructor.

Refer to this test:
https://github.com/casact/chainladder-python/blob/master/chainladder/core/tests/test_triangle.py#L352-L360

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants