Skip to content

Commit e8690a6

Browse files
committed
fixed and added top 12 german companies test
1 parent 7ae67ff commit e8690a6

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

dataframe-jupyter/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/SampleNotebooksTests.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ class SampleNotebooksTests : DataFrameJupyterTest() {
7676
},
7777
)
7878

79+
@Test
80+
fun top12GermanCompanies() =
81+
exampleTest(
82+
dir = "top_12_german_companies",
83+
replacer = CodeReplacer.byMap(
84+
testFile("top_12_german_companies", "top_12_german_companies.csv"),
85+
),
86+
)
87+
7988
private fun doTest(
8089
notebookPath: String,
8190
replacer: CodeReplacer,
@@ -95,9 +104,9 @@ class SampleNotebooksTests : DataFrameJupyterTest() {
95104
val code = codeCellData.code
96105
val codeToExecute = replacer.replace(code)
97106

98-
println("Executing code:\n$codeToExecute")
107+
// println("Executing code:\n$codeToExecute")
99108
val cellResult = execRendered(codeToExecute)
100-
println(cellResult)
109+
// println(cellResult)
101110
}
102111
} finally {
103112
cleanup()
@@ -118,7 +127,6 @@ class SampleNotebooksTests : DataFrameJupyterTest() {
118127
data class CodeCellData(val code: String, val outputs: List<Output>)
119128

120129
companion object {
121-
const val IDEA_EXAMPLES_PATH = "../examples/idea-examples"
122130
const val NOTEBOOK_EXAMPLES_PATH = "../examples/notebooks/dev"
123131

124132
fun testFile(folder: String, fileName: String) = fileName to "$NOTEBOOK_EXAMPLES_PATH/$folder/$fileName"

examples/notebooks/dev/top_12_german_companies/top_12_german_companies.ipynb

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"\n",
99
"In this notebook, we load and analyze key financial metrics for several major German companies.\n",
1010
"We perform data transformations, compute statistical measures, group by business sector, and create various plots to visualize trends in\n",
11-
"revenue, net income, return on assets (ROA), and return on equity (ROE)"
11+
"revenue, net income, return on assets (roa), and return on equity (roe)"
1212
]
1313
},
1414
{
@@ -49,7 +49,7 @@
4949
"source": [
5050
"// Read data from a CSV file into a DataFrame\n",
5151
"val dataFrame = DataFrame.read(\"top_12_german_companies.csv\")\n",
52-
" .renameToCamelCase().rename(\"rOA(%)\", \"rOE(%)\").into(\"ROA\", \"ROE\")"
52+
" .renameToCamelCase()"
5353
],
5454
"outputs": [
5555
{
@@ -198,7 +198,7 @@
198198
"val companiesDf = dataFrame\n",
199199
" .convert { period }.with { LocalDate.parse(it, format) }\n",
200200
" .convert { percentageDebtToEquity }.with { it.removeSuffix(\"%\").replace(',', '.').toDouble() }\n",
201-
" .convert { ROA and ROE }.with { it.replace(\".\", \"\").toDouble() }\n",
201+
" .convert { roa and roe }.with { it.replace(\".\", \"\").toDouble() }\n",
202202
" .sortBy { company and period }\n",
203203
" .add(\"sector\") {\n",
204204
" when (company) {\n",
@@ -230,7 +230,7 @@
230230
"cell_type": "code",
231231
"source": [
232232
"companiesDf.groupBy { company }.aggregate {\n",
233-
" val financeColumns = it.select { revenue and netIncome and liabilities and assets and equity and ROA and ROE and debtToEquity and percentageDebtToEquity }\n",
233+
" val financeColumns = it.select { revenue and netIncome and liabilities and assets and equity and roa and roe and debtToEquity and percentageDebtToEquity }\n",
234234
" financeColumns.mean() into \"mean\"\n",
235235
" financeColumns.median() into \"median\"\n",
236236
" financeColumns.std() into \"std\"\n",
@@ -247,7 +247,7 @@
247247
"source": [
248248
"// Group by \"company\" and aggregate key financial columns\n",
249249
"companiesDf.groupBy { sector }.aggregate {\n",
250-
" val financeColumns = it.select { revenue and netIncome and liabilities and assets and equity and ROA and ROE and debtToEquity and percentageDebtToEquity }\n",
250+
" val financeColumns = it.select { revenue and netIncome and liabilities and assets and equity and roa and roe and debtToEquity and percentageDebtToEquity }\n",
251251
" financeColumns.mean() into \"mean\"\n",
252252
" financeColumns.median() into \"median\"\n",
253253
" financeColumns.std() into \"std\"\n",
@@ -267,8 +267,8 @@
267267
" revenue.sum() into \"Total revenue\"\n",
268268
" netIncome.mean() into \"Avg Net Income\"\n",
269269
" netIncome.sum() into \"Sum Net Income\"\n",
270-
" ROA.mean() into \"Avg ROA\"\n",
271-
" ROE.mean() into \"Avg ROE\"\n",
270+
" roa.mean() into \"Avg roa\"\n",
271+
" roe.mean() into \"Avg roe\"\n",
272272
"}.sortBy { sector }"
273273
],
274274
"outputs": [],
@@ -428,17 +428,17 @@
428428
"metadata": {},
429429
"cell_type": "markdown",
430430
"source": [
431-
"## ROA and ROE Analysis by Sector\n",
431+
"## roa and roe Analysis by Sector\n",
432432
"\n",
433433
"1. Computing Averages and Standard Deviations:\n",
434-
" - Group the data by sector and calculate the mean and standard deviation for Return on Assets (ROA) and Return on Equity (ROE).\n",
434+
" - Group the data by sector and calculate the mean and standard deviation for Return on Assets (roa) and Return on Equity (roe).\n",
435435
" - This creates a summarized dataset for sector-level performance comparison.\n",
436-
"2. Visualizing ROA by Sector:\n",
437-
" - A bar chart displays the average ROA for each sector.\n",
436+
"2. Visualizing roa by Sector:\n",
437+
" - A bar chart displays the average roa for each sector.\n",
438438
" - Error bars represent one standard deviation, showing the variability within each sector.\n",
439-
"3. Visualizing ROE by Sector:\n",
440-
" - A similar bar chart illustrates the average ROE across sectors.\n",
441-
" - Error bars provide insight into the standard deviation of ROE within each sector.\n",
439+
"3. Visualizing roe by Sector:\n",
440+
" - A similar bar chart illustrates the average roe across sectors.\n",
441+
" - Error bars provide insight into the standard deviation of roe within each sector.\n",
442442
"\n",
443443
"These charts help compare sector-level profitability metrics and assess consistency within sectors."
444444
]
@@ -447,12 +447,12 @@
447447
"metadata": {},
448448
"cell_type": "code",
449449
"source": [
450-
"// Group data by sector to compute average and standard deviations of ROA and ROE\n",
450+
"// Group data by sector to compute average and standard deviations of roa and roe\n",
451451
"val roeAndRoaDf = companiesDf.groupBy { sector }.aggregate {\n",
452-
" ROA.mean() into \"Avg ROA\"\n",
453-
" ROA.std() into \"Std ROA\"\n",
454-
" ROE.mean() into \"Avg ROE\"\n",
455-
" ROE.std() into \"Std ROE\"\n",
452+
" roa.mean() into \"Avg roa\"\n",
453+
" roa.std() into \"Std roa\"\n",
454+
" roe.mean() into \"Avg roe\"\n",
455+
" roe.std() into \"Std roe\"\n",
456456
"}\n",
457457
"\n",
458458
"roeAndRoaDf"
@@ -464,28 +464,28 @@
464464
"metadata": {},
465465
"cell_type": "code",
466466
"source": [
467-
"// Plot average ROA by sector with error bars representing one standard deviation\n",
467+
"// Plot average roa by sector with error bars representing one standard deviation\n",
468468
"roeAndRoaDf.plot {\n",
469469
" // Set the x-axis to the sector names\n",
470470
" x(sector.map { it.simpleName }) { axis.name = \"Sector of Business\" }\n",
471471
"\n",
472472
" bars {\n",
473-
" // Use the \"Avg ROA\" column for the bar heights\n",
474-
" y(`Avg ROA`) { scale = continuous(min = .0, max = 4.5e+9) }\n",
473+
" // Use the \"Avg roa\" column for the bar heights\n",
474+
" y(`Avg roa`) { scale = continuous(min = .0, max = 4.5e+9) }\n",
475475
" // Fill bars with a chosen color\n",
476476
" fillColor = Color.hex(\"#ffaf00\")\n",
477477
" }\n",
478478
" lineRanges {\n",
479-
" // Calculate the min and max for the error bars (Std ROA)\n",
480-
" yMin(`Avg ROA`.toList().zip(`Std ROA`.toList()).map { it.first - it.second })\n",
481-
" yMax(`Avg ROA`.toList().zip(`Std ROA`.toList()).map { it.first + it.second })\n",
479+
" // Calculate the min and max for the error bars (Std roa)\n",
480+
" yMin(`Avg roa`.toList().zip(`Std roa`.toList()).map { it.first - it.second })\n",
481+
" yMax(`Avg roa`.toList().zip(`Std roa`.toList()).map { it.first + it.second })\n",
482482
" // Color the line of the ranges\n",
483483
" borderLine.color = Color.GREY\n",
484484
" }\n",
485485
"\n",
486486
" // Adjust layout options such as title and overall size\n",
487487
" layout {\n",
488-
" title = \"Average ROA By Sector With Standard Deviation\"\n",
488+
" title = \"Average roa By Sector With Standard Deviation\"\n",
489489
" size = 875 to 500\n",
490490
" }\n",
491491
"}"
@@ -497,28 +497,28 @@
497497
"metadata": {},
498498
"cell_type": "code",
499499
"source": [
500-
"// Plot average ROE by sector with error bars representing one standard deviation\n",
500+
"// Plot average roe by sector with error bars representing one standard deviation\n",
501501
"roeAndRoaDf.plot {\n",
502502
" // Set the x-axis to the sector names\n",
503503
" x(sector.map { it.simpleName }) { axis.name = \"Sector of Business\" }\n",
504504
"\n",
505505
" bars {\n",
506-
" // Use the \"Avg ROE\" column for the bar heights\n",
507-
" y(`Avg ROE`)\n",
506+
" // Use the \"Avg roe\" column for the bar heights\n",
507+
" y(`Avg roe`)\n",
508508
" // Fill bars with a chosen color\n",
509509
" fillColor = Color.hex(\"#ffaf00\")\n",
510510
" }\n",
511511
" lineRanges {\n",
512-
" // Calculate the min and max for the error bars (Std ROE)\n",
513-
" yMin(`Avg ROE`.toList().zip(`Std ROE`.toList()).map { it.first - it.second })\n",
514-
" yMax(`Avg ROE`.toList().zip(`Std ROE`.toList()).map { it.first + it.second })\n",
512+
" // Calculate the min and max for the error bars (Std roe)\n",
513+
" yMin(`Avg roe`.toList().zip(`Std roe`.toList()).map { it.first - it.second })\n",
514+
" yMax(`Avg roe`.toList().zip(`Std roe`.toList()).map { it.first + it.second })\n",
515515
" // Color the line of the ranges\n",
516516
" borderLine.color = Color.GREY\n",
517517
" }\n",
518518
"\n",
519519
" // Adjust layout options such as title and overall size\n",
520520
" layout {\n",
521-
" title = \"Average ROE By Sector With Standard Deviation\"\n",
521+
" title = \"Average roe By Sector With Standard Deviation\"\n",
522522
" size = 875 to 500\n",
523523
" }\n",
524524
"}"

0 commit comments

Comments
 (0)