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
to_frame() with index as datetime #92
Comments
Didn't copy the output since it's mostly graphical. But I'm using CL: 0.7.1 PD:1.0.3 NP: 1.18.1 PlotlyExpress: 4.9.0 |
This makes sense as an additon. I've run into this myself. There is more flexibility in option 2 so I like that one better. Did you want to take a crack at this? |
It may need tb be an 'origin_astype' argument rather than 'index_astype'. The import chainladder as cl
clrd = cl.load_sample('clrd')
clrd.latest_diagonal['CumPaidLoss'].to_frame() |
@jbogaardt I agree with the origin as type. Somewhat confusing with the difference between a period index and a periodArray. I tried to implement directly with the .astype() as above, so the user can define type and get a regular and familiar type error. But that only worked on the index, and not when I try to directly edit odims with type pandas series. My suggestion is to edit the _repr_date_axes function, and only with "origin_as_datetime" with boolean value. In that regard, when does the else clause here kick in? What type is it then?
My suggestion is to just pass one parameter.
And since the function is used only in the to_frame() function it should not result in much code change: |
I think that would work. The The def _repr_date_axes(self, origin_dtype=None):
if type(self.odims[0]) == np.datetime64:
odims = pd.Series(self.odims).dt.to_period(self.origin_grain)
else:
odims = pd.Series(self.odims)
if origin_dtype:
odims = odims.astype(origin_dtype)
One possible scenario |
Nevermind on my suggestion, I see your point on PeriodArray vs PeriodIndex - weird pandas stuff. One other suggestion would be to set to the timestamp at the end of the period |
Trying some make a frontend in use for analytical purposes with the chainladder package. And while period index is good in many case, many visiualization tools don't like them with the error "Object of type Period is not JSON serializable". This includes streamlit and dash/plotly.
Even if it's quite easy to fix - could it be a idea with a "convert_index" option in the to_frame() method?
Now this works:
This breaks:
px.line(mack.summary_['Paid'].to_frame())
would like to do:
px.line(mack.summary_['Paid'].to_frame(convert_index=True)
or
px.line(mack.summary_['Paid'].to_frame(index_astype='date'))
The text was updated successfully, but these errors were encountered: