Package: caradoc
CaradocPython utilities for doing data analysis. Named forCaradoc Vreichvras, a knight of the round table.Currently includes two utilities:FinancialYearRepresents a Financial Year, from a string in the format "2020-21".Usage:fromcaradocimportFinancialYearfy=FinancialYear("2020-21")fy+1# FinancialYear("2021-22")fy-1# FinancialYear("2019-20")str(fy)# "2020-21"int(fy)# 2020Create from date or yearfromdatetimeimportdatefromcaradocimportFinancialYearfy=FinancialYear.from_date(date(2020,1,1))str(fy)# "2019-20"fy=FinancialYear.from_int(2020)str(fy)# "2020-21"Useful utilities:fromcaradocimportFinancialYearfy=FinancialYear("2020-21")fy.previous_n_years(4)# [#    FinancialYear("2016-17"),#    FinancialYear("2017-18"),#    FinancialYear("2018-19"),#    FinancialYear("2019-20"),#    FinancialYear("2020-21")# ]FinancialYear.range("2018-19","2020-21")# [#    FinancialYear("2018-19"),#    FinancialYear("2019-20"),#    FinancialYear("2020-21"),# ]d=date(2021,6,1)dinFinancialYear("2021-22")# TruedinFinancialYear("2020-22")# FalseCurrently years are hardcoded to end on 31st March but this will be changed.ExcelTableRepresents a table in an Excel workbook.The table itself is a pandas DataFrame. The DataFrame index is not written to the Excel file.Allows for specifying a title, summary and notes for the table.Parametersdf: pandas DataFrametitle: Optional title for the tablesummary: Optional summary for the tablenotes: Optional notes for the tableMethodsto_excel_table(): Writes just the datatable (df) to an Excel file as a Table (with filters)to_excel(): Writes the table to an Excel file as a Table, with the
title and summary as a header and the notes as a footer.UsagefromcaradocimportExcelTableimportpandasaspddf=pd.DataFrame({"alice":[1,2,3],"bob":[4,5,6]})et=ExcelTable(df,title="Test Table")withpd.ExcelWriter("test_file.xlsx",engine="auto")aswriter:et.to_excel(writer,"test_sheet")Output looks something like:AB1Test Table23AliceBob414525636You can also include a summary (underneath the title) and notes (underneath the table) usingsummary=andnotes=DataOutputRepresents a collection of ExcelTables to be written to an Excel file.Methodsadd_table(): Adds a table to the DataOutputwrite(): Writes the DataOutput to an Excel fileUsagefromcaradocimportDataOutput,ExcelTableimportpandasaspdoutput=DataOutput()df1=pd.DataFrame({"alice":[1,2,3],"bob":[4,5,6]})table1=ExcelTable(df1,title="Test Table")output.add_table("test_sheet",table1)df2=pd.DataFrame({"alice":[1,2,3],"bob":[4,5,6]})output.add_table("test_sheet",df2,title="Test Table 2")output.write("test_file.xlsx")Output oftest_file.xlsxwill be an excel workbook with a sheet called "test_sheet". The sheet will have two tables, each table with a title and spacing between them.DevelopmentRun testsTests can be run withpytest:hatchruntestTest coveragehatchruncov-htmlRun typing checkshatchrunlint:typingLintingBlack and ruff should be run before committing any changes.hatchrunlint:styleRun all checks at oncehatchrunlint:allPublish to pypipython-mbuild
twineuploaddist/*
gittagv<VERSION_NUMBER>
gitpushoriginv<VERSION_NUMBER>Install development versionThe development requirements are installed usingpip install -r dev-requirements.txt.Any additional requirements for the module itself must be added toinstall_requiresinsetup.py. You should then generate a newrequirements.txtusing usingpip-tools(pip-compile). You can then runpip-syncto install the
requirement.Any additional development requirements must be added todev-requirements.inand then thedev-requirements.txtshould be generated usingpip-compile dev-requirements.in. You can then install the development requirements usingpip-sync dev-requirements.txt.