Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
268 changes: 268 additions & 0 deletions branch_nb.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 71,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from chalk.client import ChalkClient\n",
"from chalk.features import features, online, has_one, DataFrame\n",
"from typing import Optional\n",
"\n",
"\n",
"c = ChalkClient(branch=\"main2\")"
]
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 72,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uploading 1 feature class to branch server...\n",
"*\tfeature: card_account_fs.id\n",
"*\tfeature: card_account_fs.some_card_feature\n"
]
}
],
"source": [
"@features\n",
"class CardAccountFS:\n",
" id: int\n",
"\n",
" some_card_feature: str\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 79,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uploading 1 feature class to branch server...\n",
"*\tfeature: funding_source.bank_account_id\n",
"*\tfeature: funding_source.card_account\n",
"*\tfeature: funding_source.card_account_id\n",
"*\tfeature: funding_source.funding_source_type\n",
"*\tfeature: funding_source.id\n",
"*\tfeature: funding_source.some_feature\n"
]
}
],
"source": [
"@features\n",
"class FundingSource:\n",
" id: int\n",
" card_account_id: Optional[int]\n",
" bank_account_id: Optional[int]\n",
" funding_source_type: str # card or account\n",
"\n",
" some_feature: Optional[str]\n",
"\n",
" card_account: Optional[CardAccountFS] = has_one(lambda: CardAccountFS.id == FundingSource.card_account_id)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 74,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uploading 1 resolver to branch server...\n",
"*\tresolver: funding_source_type\n"
]
}
],
"source": [
"@online\n",
"def funding_source_type(\n",
" funding_source_type: FundingSource.funding_source_type,\n",
" card_account_feature: Optional[FundingSource.card_account.some_card_feature]\n",
") -> FundingSource.some_feature:\n",
" return card_account_feature"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 75,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uploading 1 resolver to branch server...\n",
"*\tresolver: get_card_accounts\n"
]
}
],
"source": [
"@online\n",
"def get_card_accounts() -> DataFrame[CardAccountFS.id, CardAccountFS.some_card_feature]:\n",
" return DataFrame([\n",
" CardAccountFS(id=100, some_card_feature=\"Something\")\n",
" ])"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 76,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uploading 1 resolver to branch server...\n",
"*\tresolver: get_funding_sources\n"
]
}
],
"source": [
"@online\n",
"def get_funding_sources() -> DataFrame[FundingSource.id, FundingSource.funding_source_type, FundingSource.card_account_id, FundingSource.bank_account_id]:\n",
" return DataFrame([\n",
" FundingSource(id=1, funding_source_type=\"card\", card_account_id=100, bank_account_id=None),\n",
" FundingSource(id=2, funding_source_type=\"bank_account\", card_account_id=None, bank_account_id=1000)\n",
" ])"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 81,
"outputs": [
{
"data": {
"text/plain": " Feature Value\n0 funding_source.id 1\n1 funding_source.card_account_id 100\n2 funding_source.some_feature Something\n3 funding_source.bank_account_id None\n4 funding_source.funding_source_type card",
"text/markdown": "\n## Features\n```\n┌───────────────────────────────────┬───────────┐\n│ Feature ┆ Value │\n╞═══════════════════════════════════╪═══════════╡\n│ funding_source.id ┆ 1 │\n│ funding_source.card_account_id ┆ 100 │\n│ funding_source.some_feature ┆ Something │\n│ funding_source.bank_account_id ┆ null │\n│ funding_source.funding_source_ty… ┆ card │\n└───────────────────────────────────┴───────────┘\n```"
},
"execution_count": 81,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.query(input={FundingSource.id: 1}, output=[FundingSource.id, FundingSource.funding_source_type, FundingSource.bank_account_id, FundingSource.card_account_id, FundingSource.some_feature], explain=True)\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 82,
"outputs": [
{
"data": {
"text/plain": " Feature Value\n0 funding_source.id 2\n1 funding_source.card_account_id None\n2 funding_source.some_feature None\n3 funding_source.bank_account_id 1000\n4 funding_source.funding_source_type bank_account",
"text/markdown": "\n## Features\n```\n┌───────────────────────────────────┬──────────────┐\n│ Feature ┆ Value │\n╞═══════════════════════════════════╪══════════════╡\n│ funding_source.id ┆ 2 │\n│ funding_source.card_account_id ┆ null │\n│ funding_source.some_feature ┆ null │\n│ funding_source.bank_account_id ┆ 1000 │\n│ funding_source.funding_source_ty… ┆ bank_account │\n└───────────────────────────────────┴──────────────┘\n```"
},
"execution_count": 82,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.query(input={FundingSource.id: 2}, output=[FundingSource.id, FundingSource.funding_source_type, FundingSource.bank_account_id, FundingSource.card_account_id, FundingSource.some_feature], explain=True)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}