Skip to content

Commit f394360

Browse files
Fix min Python version in README for 0.9 series (#642)
* Fix min Python version in README for 0.9 series * Minor fixes in the readme example model * Spacing
1 parent 13a10c5 commit f394360

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tracdap-runtime/python/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ For a complete guide to writing models in the TRAC framework, see the
4545

4646
## 📦 Requirements
4747

48-
* **Python :** 3.10 or later
48+
* **Python :** 3.9 or later
4949
* **Tools :** Any popular IDE (PyCharm, VS Code, etc.)
5050
* **Pandas :** Version 1.2 and later are supported
5151
* **Polars :** Version 1.0 and later are supported
@@ -72,35 +72,35 @@ import tracdap.rt.api as trac
7272
class QuickStartModel(trac.TracModel):
7373

7474
def define_parameters(self):
75-
75+
7676
# Define any parameters the model will use
7777
return trac.define_parameters(
7878
trac.P("exchange_rate", trac.FLOAT, "EUR / GBP exchange rate")
7979
)
8080

8181
def define_inputs(self):
82-
82+
8383
# Define an input table with the columns and data types that the model needs
8484
customer_loans = trac.define_input_table(
8585
trac.F("id", trac.STRING, label="Customer account ID", business_key=True),
8686
trac.F("region", trac.STRING, label="Customer home region", categorical=True),
87-
trac.F("loan_amount", trac.FLOAT, label="Principal loan amount"),
87+
trac.F("loan_amount", trac.FLOAT, label="Principal loan amount (EUR)"),
8888
label="Customer loans data")
8989

9090
return {"customer_loans": customer_loans}
9191

9292
def define_outputs(self):
93-
93+
9494
# Define an output table with the columns and data types that the model will produce
9595
loans_by_region = trac.define_output_table(
9696
trac.F("region", trac.STRING, label="Customer home region", categorical=True),
97-
trac.F("loan_amount", trac.FLOAT, label="Principal loan amount"),
97+
trac.F("total_lending", trac.FLOAT, label="Total lending (GBP)"),
9898
label="Loans by region")
9999

100100
return {"loans_by_region": loans_by_region}
101101

102102
def run_model(self, ctx: trac.TracContext):
103-
103+
104104
# Parameters and inputs are loaded and validated by TRAC
105105
exchange_rate = ctx.get_parameter("exchange_rate")
106106
customer_loans = ctx.get_pandas_table("customer_loans")
@@ -109,11 +109,11 @@ class QuickStartModel(trac.TracModel):
109109
customer_loans["loan_amount_gbp"] = customer_loans["loan_amount"] * exchange_rate
110110

111111
loans_by_region = customer_loans \
112-
.groupby("region", as_index=False) \
113-
.aggregate({"loan_amount": "sum"})
112+
.groupby("region", observed=True, as_index=False) \
113+
.aggregate(total_lending=("loan_amount_gbp", "sum"))
114114

115115
# Logs written to ctx.log are captured by the platform
116-
ctx.log().info("Aggregated loans for {} regions", len(loans_by_region))
116+
ctx.log().info("Aggregated loans for %d regions", len(loans_by_region))
117117

118118
# Outputs are handed back to TRAC for validation and saving
119119
ctx.put_pandas_table("loans_by_region", loans_by_region)

0 commit comments

Comments
 (0)