From e7d57eefd88df29f78f608250462711286b7a6fd Mon Sep 17 00:00:00 2001 From: James Turk Date: Sat, 14 Dec 2024 14:17:33 -0600 Subject: [PATCH] final for quarter --- 18.testing.ipynb | 9 +++++++-- 19.scientific-python.ipynb | 34 +++++++++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/18.testing.ipynb b/18.testing.ipynb index f9df323..434ba07 100644 --- a/18.testing.ipynb +++ b/18.testing.ipynb @@ -96,7 +96,7 @@ " # centered at origin, radius 1\n", " result = circle_contains(1, origin, origin)\n", " assert result\n", - " assert circle_contains(1, origin, Point(.5, .5))\n", + " assert circle_contains(1, origin, Point(.5, .5)), \"circle should contain 0.5, 0.5\"\n", "\n", "def test_circle_contains_edge():\n", " assert circle_contains(1, origin, Point(1, 0)) # on the circle\n", @@ -440,6 +440,7 @@ " (\"abc\", \"abd\", 1),\n", " (\"abc\", \"abc\", 0),\n", " (\"abc\", \"xyz\", 3),\n", + " (\"abc\", \"abcd\", 1),\n", "])\n", "def test_hamming_distance(str1, str2, expected):\n", " assert hamming_distance(str1, str2) == expected\n", @@ -453,7 +454,11 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "test_hamming_distance[abc-abd-1]\n", + "test_hamming_distance[abc-abc-0]\n", + "test_hamming_distance[abc-xyz-3]" + ] } ], "metadata": { diff --git a/19.scientific-python.ipynb b/19.scientific-python.ipynb index bcd3058..5609289 100644 --- a/19.scientific-python.ipynb +++ b/19.scientific-python.ipynb @@ -261,7 +261,7 @@ "source": [ "import numpy as np\n", "print(np.array([1, 2, 3, 4, 5])) \n", - "print(np.array([1, 2, 3, 4., 5])) # one float will make the entire array floats" + "print(np.array([1, 2, 3, 4.0, 5])) # one float will make the entire array floats" ] }, { @@ -712,7 +712,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 3, "id": "eb390bd2-00e6-452a-9ff6-a9bc8d39d8b8", "metadata": {}, "outputs": [], @@ -747,7 +747,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 4, "id": "6037f4be-9df6-43a5-bc0e-28540fa9cea1", "metadata": {}, "outputs": [], @@ -775,7 +775,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 5, "id": "19fea8cf-93ee-422b-b8c1-93f868c1a1f8", "metadata": {}, "outputs": [], @@ -801,7 +801,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 6, "id": "6aa5a845-a38f-41c0-8be4-a2a10c184511", "metadata": {}, "outputs": [ @@ -815,9 +815,9 @@ "│ --- ┆ --- │\n", "│ str ┆ f64 │\n", "╞════════════════╪═════════════════════╡\n", - "│ Pure Python ┆ 228.155336 │\n", - "│ Pandas ┆ 88.117557 │\n", - "│ Polars ┆ 8.866674 │\n", + "│ Pure Python ┆ 238.297975 │\n", + "│ Pandas ┆ 86.9603 │\n", + "│ Polars ┆ 10.461535 │\n", "└────────────────┴─────────────────────┘\n" ] } @@ -836,7 +836,7 @@ " return timeit.timeit(lambda: func(*args), number=iterations) / iterations\n", "\n", "# time each function\n", - "ITERATIONS = 100\n", + "ITERATIONS = 20\n", "python_time = avg_time(find_bills_pure_python, BILLS_FILE, LEGISLATORS_FILE, SPONSORSHIPS_FILE, TARGET_NAME, iterations=ITERATIONS)\n", "pandas_time = avg_time(find_bills_pandas, BILLS_FILE, LEGISLATORS_FILE, SPONSORSHIPS_FILE, TARGET_NAME, iterations=ITERATIONS)\n", "polars_time = avg_time(find_bills_polars, BILLS_FILE, LEGISLATORS_FILE, SPONSORSHIPS_FILE, TARGET_NAME, iterations=ITERATIONS)\n", @@ -852,7 +852,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 7, "id": "17c75df4-4d7b-45b5-be21-56fd80f81ff6", "metadata": {}, "outputs": [ @@ -861,23 +861,23 @@ "text/html": [ "\n", "\n", - "
\n", + "
\n", "" ], "text/plain": [