|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "b7ec8b49-2fd0-4096-adbf-bb8b788e51cb", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "%run pandas_implementation" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": 6, |
| 16 | + "id": "09200a47-86b3-479f-8bbb-dc0fb3339978", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "%run vaex_implementation_v1" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "code", |
| 25 | + "execution_count": 7, |
| 26 | + "id": "d710a2f5-fa03-4af2-a143-a4b441c43b48", |
| 27 | + "metadata": {}, |
| 28 | + "outputs": [], |
| 29 | + "source": [ |
| 30 | + "import ipytest\n", |
| 31 | + "ipytest.autoconfig()" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": 9, |
| 37 | + "id": "8019a01a-2243-4b58-bb0e-db277ed34038", |
| 38 | + "metadata": {}, |
| 39 | + "outputs": [ |
| 40 | + { |
| 41 | + "name": "stdout", |
| 42 | + "output_type": "stream", |
| 43 | + "text": [ |
| 44 | + "Data: Vaex and pointer\n", |
| 45 | + "Step 1: Vaex (from_dataframe_to_vaex) and pointer\n", |
| 46 | + " # x y\n", |
| 47 | + " 0 1.5 9.2\n", |
| 48 | + " 1 2.5 10.5\n", |
| 49 | + " 2 3.5 11.8\n", |
| 50 | + "2042418436992\n", |
| 51 | + "Step 2: Pandas (from_dataframe) and pointer\n", |
| 52 | + " x y\n", |
| 53 | + "0 1.5 9.2\n", |
| 54 | + "1 2.5 10.5\n", |
| 55 | + "2 3.5 11.8\n", |
| 56 | + "2042418436992\n", |
| 57 | + "Step 3: Vaex (from_dataframe_to_vaex) and pointer\n", |
| 58 | + " # x y\n", |
| 59 | + " 0 1.5 9.2\n", |
| 60 | + " 1 2.5 10.5\n", |
| 61 | + " 2 3.5 11.8\n", |
| 62 | + "2042418436992\n", |
| 63 | + ".\n", |
| 64 | + "1 passed in 0.01s\n" |
| 65 | + ] |
| 66 | + } |
| 67 | + ], |
| 68 | + "source": [ |
| 69 | + "%%run_pytest[clean] -s\n", |
| 70 | + "# Testing roundtrip\n", |
| 71 | + "# data -> Vaex -> Vaex (from_dataframe_to_vaex) -> Pandas (from_dataframe) -> Vaex (from_dataframe_to_vaex)\n", |
| 72 | + "\n", |
| 73 | + "def test_roundtrip():\n", |
| 74 | + " \n", |
| 75 | + " # Test data\n", |
| 76 | + " x = np.array([1.5, 2.5, 3.5])\n", |
| 77 | + " y = np.array([9.2, 10.5, 11.8])\n", |
| 78 | + " df = vaex.from_arrays(x=x, y=y)\n", |
| 79 | + " \n", |
| 80 | + " print(\"Data: Vaex and pointer\")\n", |
| 81 | + " b0 = df.x.to_numpy().__array_interface__['data'][0]\n", |
| 82 | + " \n", |
| 83 | + " # Step 1\n", |
| 84 | + " print(\"Step 1: Vaex (from_dataframe_to_vaex) and pointer\")\n", |
| 85 | + " df1 = from_dataframe_to_vaex(df)\n", |
| 86 | + " b1 = df1.x.to_numpy().__array_interface__['data'][0]\n", |
| 87 | + " \n", |
| 88 | + " print(df1)\n", |
| 89 | + " print(b1)\n", |
| 90 | + " \n", |
| 91 | + " # Step 2\n", |
| 92 | + " print(\"Step 2: Pandas (from_dataframe) and pointer\")\n", |
| 93 | + " df2 = from_dataframe(df1)\n", |
| 94 | + " b2 = df2.x.to_numpy().__array_interface__['data'][0]\n", |
| 95 | + " \n", |
| 96 | + " print(df2)\n", |
| 97 | + " print(b2)\n", |
| 98 | + " \n", |
| 99 | + " # Step 3\n", |
| 100 | + " print(\"Step 3: Vaex (from_dataframe_to_vaex) and pointer\")\n", |
| 101 | + " df3 = from_dataframe_to_vaex(df2)\n", |
| 102 | + " b3 = df3.x.to_numpy().__array_interface__['data'][0]\n", |
| 103 | + " \n", |
| 104 | + " print(df3)\n", |
| 105 | + " print(b3)\n", |
| 106 | + " \n", |
| 107 | + " assert b0 == b3" |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "execution_count": 11, |
| 113 | + "id": "26ff0e15-a4d8-4828-b715-205d5ce9d5d4", |
| 114 | + "metadata": {}, |
| 115 | + "outputs": [ |
| 116 | + { |
| 117 | + "name": "stdout", |
| 118 | + "output_type": "stream", |
| 119 | + "text": [ |
| 120 | + "\n", |
| 121 | + "Dataframes before value change:\n", |
| 122 | + "\n", |
| 123 | + " # x y\n", |
| 124 | + " 0 1.5 9.2\n", |
| 125 | + " 1 2.5 10.5\n", |
| 126 | + " 2 3.5 11.8\n", |
| 127 | + " # x y\n", |
| 128 | + " 0 1.5 9.2\n", |
| 129 | + " 1 2.5 10.5\n", |
| 130 | + " 2 3.5 11.8\n", |
| 131 | + "\n", |
| 132 | + "After value change\n", |
| 133 | + "\n", |
| 134 | + " # x y\n", |
| 135 | + " 0 333 9.2\n", |
| 136 | + " 1 2.5 10.5\n", |
| 137 | + " 2 3.5 11.8\n", |
| 138 | + " # x y\n", |
| 139 | + " 0 1.5 9.2\n", |
| 140 | + " 1 2.5 10.5\n", |
| 141 | + " 2 3.5 11.8\n", |
| 142 | + "\n", |
| 143 | + "After another value change\n", |
| 144 | + "\n", |
| 145 | + " # x y\n", |
| 146 | + " 0 333 9.2\n", |
| 147 | + " 1 2.5 10.5\n", |
| 148 | + " 2 3.5 11.8\n", |
| 149 | + " # x y\n", |
| 150 | + " 0 1.5 9.2\n", |
| 151 | + " 1 2.5 10.5\n", |
| 152 | + " 2 3.5 777\n", |
| 153 | + ".\n", |
| 154 | + "================================================== warnings summary ===================================================\n", |
| 155 | + "tmp3gafiquy.py: 16 warnings\n", |
| 156 | + " C:\\Users\\Alenka\\anaconda3\\envs\\df_protocol\\lib\\ast.py:407: DeprecationWarning: visit_Num is deprecated; add visit_Constant\n", |
| 157 | + " return visitor(node)\n", |
| 158 | + "\n", |
| 159 | + "-- Docs: https://docs.pytest.org/en/stable/warnings.html\n", |
| 160 | + "1 passed, 16 warnings in 0.03s\n" |
| 161 | + ] |
| 162 | + } |
| 163 | + ], |
| 164 | + "source": [ |
| 165 | + "%%run_pytest[clean] -s\n", |
| 166 | + "# Cheking value changes\n", |
| 167 | + "# See if it affects the other object also\n", |
| 168 | + "# (if the buffer is the same, data should be changed on both df and df2\n", |
| 169 | + "\n", |
| 170 | + "def test_value_change():\n", |
| 171 | + " \n", |
| 172 | + " # Test data\n", |
| 173 | + " x = np.array([1.5, 2.5, 3.5])\n", |
| 174 | + " y = np.array([9.2, 10.5, 11.8])\n", |
| 175 | + " df = vaex.from_arrays(x=x, y=y)\n", |
| 176 | + " \n", |
| 177 | + " # Step 1\n", |
| 178 | + " df1 = from_dataframe_to_vaex(df)\n", |
| 179 | + " \n", |
| 180 | + " # Step 2\n", |
| 181 | + " df2 = from_dataframe(df1)\n", |
| 182 | + " \n", |
| 183 | + " # Step 3\n", |
| 184 | + " df3 = from_dataframe_to_vaex(df2)\n", |
| 185 | + " \n", |
| 186 | + " print(\"\\nDataframes before value change:\\n\")\n", |
| 187 | + " print(df)\n", |
| 188 | + " print(df3)\n", |
| 189 | + "\n", |
| 190 | + " print(\"\\nAfter value change\\n\")\n", |
| 191 | + " df['x'] = df.func.where(df.x == 1.5, 333, df.x)\n", |
| 192 | + " print(df)\n", |
| 193 | + " print(df3)\n", |
| 194 | + "\n", |
| 195 | + " print(\"\\nAfter another value change\\n\")\n", |
| 196 | + " df3['y'] = df3.func.where(df3.y == 11.8, 777, df3.y)\n", |
| 197 | + " print(df)\n", |
| 198 | + " print(df3)" |
| 199 | + ] |
| 200 | + }, |
| 201 | + { |
| 202 | + "cell_type": "code", |
| 203 | + "execution_count": null, |
| 204 | + "id": "b048fffb-34fa-4591-8225-686c3d6e0fb4", |
| 205 | + "metadata": {}, |
| 206 | + "outputs": [], |
| 207 | + "source": [] |
| 208 | + } |
| 209 | + ], |
| 210 | + "metadata": { |
| 211 | + "kernelspec": { |
| 212 | + "display_name": "Python 3", |
| 213 | + "language": "python", |
| 214 | + "name": "python3" |
| 215 | + }, |
| 216 | + "language_info": { |
| 217 | + "codemirror_mode": { |
| 218 | + "name": "ipython", |
| 219 | + "version": 3 |
| 220 | + }, |
| 221 | + "file_extension": ".py", |
| 222 | + "mimetype": "text/x-python", |
| 223 | + "name": "python", |
| 224 | + "nbconvert_exporter": "python", |
| 225 | + "pygments_lexer": "ipython3", |
| 226 | + "version": "3.9.5" |
| 227 | + } |
| 228 | + }, |
| 229 | + "nbformat": 4, |
| 230 | + "nbformat_minor": 5 |
| 231 | +} |
0 commit comments