Skip to content

Commit

Permalink
Reduction of if statements
Browse files Browse the repository at this point in the history
Co-authored-by: Audrey Roy Greenfeld <arg@answer.ai>
  • Loading branch information
pydanny and audreyfeldroy committed Nov 20, 2024
1 parent c62e43b commit e33b43b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
3 changes: 1 addition & 2 deletions fastlite/kw.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,9 @@ def insert(
columns: Union[Dict[str, Any], Default, None]=DEFAULT,
strict: opt_bool=DEFAULT,
**kwargs) -> Table:
if not kwargs and not record: return {}
if not kwargs and asdict(record) == {}: return {}
record = _process_row(record)
record = {**record, **kwargs}
if not record: return {}
self._orig_insert(
record=record, pk=pk, foreign_keys=foreign_keys, column_order=column_order, not_null=not_null,
defaults=defaults, hash_id=hash_id, hash_id_columns=hash_id_columns, alter=alter, ignore=ignore,
Expand Down
80 changes: 46 additions & 34 deletions nbs/test_insert.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "ad470f25",
"metadata": {},
"outputs": [],
Expand All @@ -36,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "97dd1b48",
"metadata": {},
"outputs": [],
Expand All @@ -46,7 +46,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "5102a3ac",
"metadata": {},
"outputs": [],
Expand All @@ -56,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "9188c149",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -98,7 +98,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "fba0c4f7",
"metadata": {},
"outputs": [
Expand All @@ -108,7 +108,7 @@
"{}"
]
},
"execution_count": null,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -127,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "ace59c88",
"metadata": {},
"outputs": [],
Expand All @@ -147,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "a93ec70a",
"metadata": {},
"outputs": [],
Expand All @@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "79cd5186",
"metadata": {},
"outputs": [],
Expand All @@ -173,7 +173,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "aa988175",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -203,7 +203,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "1fdd0aaf",
"metadata": {},
"outputs": [],
Expand All @@ -221,7 +221,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "c736aa0f",
"metadata": {},
"outputs": [],
Expand All @@ -239,7 +239,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "cfd90ab0",
"metadata": {},
"outputs": [],
Expand All @@ -261,7 +261,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "72a25f8d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -300,7 +300,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "5a968d13",
"metadata": {},
"outputs": [],
Expand All @@ -319,7 +319,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "92d53608",
"metadata": {},
"outputs": [],
Expand All @@ -330,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"id": "51cb29b1",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -368,7 +368,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"id": "972bab86",
"metadata": {},
"outputs": [],
Expand All @@ -387,7 +387,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "55364dd6",
"metadata": {},
"outputs": [],
Expand All @@ -407,7 +407,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"id": "45a4c2aa",
"metadata": {},
"outputs": [],
Expand All @@ -425,7 +425,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"id": "07c034e9",
"metadata": {},
"outputs": [],
Expand All @@ -435,7 +435,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"id": "963008b6",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -480,7 +480,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"id": "c8a95079",
"metadata": {},
"outputs": [],
Expand All @@ -500,7 +500,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"id": "cee37620",
"metadata": {},
"outputs": [],
Expand All @@ -522,7 +522,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"id": "98118662",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -551,7 +551,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"id": "96632dfb",
"metadata": {},
"outputs": [],
Expand All @@ -571,7 +571,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"id": "b110b0a7",
"metadata": {},
"outputs": [],
Expand All @@ -592,7 +592,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"id": "803e6bc9",
"metadata": {},
"outputs": [],
Expand All @@ -614,7 +614,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"id": "570d5dce",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -645,7 +645,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"id": "ca76eb12",
"metadata": {},
"outputs": [],
Expand All @@ -671,7 +671,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"id": "5a37e482",
"metadata": {},
"outputs": [],
Expand All @@ -696,7 +696,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"id": "da81a215",
"metadata": {},
"outputs": [],
Expand All @@ -721,7 +721,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 32,
"id": "9d7d7991",
"metadata": {},
"outputs": [],
Expand All @@ -735,9 +735,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit e33b43b

Please sign in to comment.