This is an automated email from the ASF dual-hosted git repository. rusackas pushed a commit to branch more-notebook-tweaks in repository https://gitbox.apache.org/repos/asf/superset.git
commit d3b5d5d090f56666f53624bab34ba525b13040a6 Author: Evan Rusackas <[email protected]> AuthorDate: Thu Mar 21 23:19:07 2024 -0600 using temp directory --- .../scripts/Country Map GeoJSON Generator.ipynb | 104 +++++++++++++++++++-- 1 file changed, 94 insertions(+), 10 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb b/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb index 28e9142552..637f53648c 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb +++ b/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -63,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -71,11 +71,25 @@ "id": "VjGrqW4Kt1LS", "outputId": "2e2accda-5ee4-4270-872e-ecb78d0d02a2" }, - "outputs": [], - "source": [ - "data_dir = os.path.expanduser(\"~/Downloads\")\n", - "if not os.path.exists(data_dir):\n", - " os.mkdir(data_dir)\n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Error downloading files. Please open the URL to download them from browser manually.\n", + "Done. \n" + ] + } + ], + "source": [ + "# Get the directory of this notebook\n", + "notebook_dir = os.getcwd()\n", + "\n", + "# Construct the relative path to the directory alongside the notebook in /tmp\n", + "data_dir = os.path.join(notebook_dir, 'tmp_geojson')\n", + "\n", + "# Ensure the directory exists, if not, create it\n", + "os.makedirs(data_dir, exist_ok=True)\n", "\n", "def download_files(skip_existing=True):\n", " for url in [\n", @@ -114,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -122,7 +136,31 @@ "id": "EL0e9DEVt1LT", "outputId": "16cd6450-d4a3-457a-b205-9797bbce33fc" }, - "outputs": [], + "outputs": [ + { + "ename": "DriverError", + "evalue": "'/vsizip//Users/evan_1/GitHub/superset/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/tmp_geojson/ne_10m_admin_0_countries.zip' does not exist in the file system, and is not recognized as a supported dataset name.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mCPLE_OpenFailedError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32mfiona/ogrext.pyx:136\u001b[0m, in \u001b[0;36mfiona.ogrext.gdal_open_vector\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_err.pyx:291\u001b[0m, in \u001b[0;36mfiona._err.exc_wrap_pointer\u001b[0;34m()\u001b[0m\n", + "\u001b[0;31mCPLE_OpenFailedError\u001b[0m: '/vsizip//Users/evan_1/GitHub/superset/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/tmp_geojson/ne_10m_admin_0_countries.zip' does not exist in the file system, and is not recognized as a supported dataset name.", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mDriverError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[9], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Read Natural Earth data files into GeoDataFrames\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m df_admin0_10m \u001b[38;5;241m=\u001b[39m \u001b[43mgpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread_file\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mdata_dir\u001b[49m\u001b[38;5;132;43;01 [...] + "File \u001b[0;32m/usr/local/lib/python3.11/site-packages/geopandas/io/file.py:297\u001b[0m, in \u001b[0;36m_read_file\u001b[0;34m(filename, bbox, mask, rows, engine, **kwargs)\u001b[0m\n\u001b[1;32m 294\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 295\u001b[0m path_or_bytes \u001b[38;5;241m=\u001b[39m filename\n\u001b[0;32m--> 297\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_read_file_fiona\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1; [...] + "File \u001b[0;32m/usr/local/lib/python3.11/site-packages/geopandas/io/file.py:338\u001b[0m, in \u001b[0;36m_read_file_fiona\u001b[0;34m(path_or_bytes, from_bytes, bbox, mask, rows, where, **kwargs)\u001b[0m\n\u001b[1;32m 335\u001b[0m reader \u001b[38;5;241m=\u001b[39m fiona\u001b[38;5;241m.\u001b[39mopen\n\u001b[1;32m 337\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m fiona_env():\n\u001b[0;32m--> 338\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[43mreader\u001b[ [...] + "File \u001b[0;32m/usr/local/lib/python3.11/site-packages/fiona/env.py:457\u001b[0m, in \u001b[0;36mensure_env_with_credentials.<locals>.wrapper\u001b[0;34m(*args, **kwds)\u001b[0m\n\u001b[1;32m 454\u001b[0m session \u001b[38;5;241m=\u001b[39m DummySession()\n\u001b[1;32m 456\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m env_ctor(session\u001b[38;5;241m=\u001b[39msession):\n\u001b[0;32m--> 457\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf\u001b[49m\u001b[4 [...] + "File \u001b[0;32m/usr/local/lib/python3.11/site-packages/fiona/__init__.py:292\u001b[0m, in \u001b[0;36mopen\u001b[0;34m(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, allow_unsupported_drivers, **kwargs)\u001b[0m\n\u001b[1;32m 289\u001b[0m path \u001b[38;5;241m=\u001b[39m parse_path(fp)\n\u001b[1;32m 291\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m mode \u001b[38;5;129;01min\u001b[39;00m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[ [...] + "File \u001b[0;32m/usr/local/lib/python3.11/site-packages/fiona/collection.py:243\u001b[0m, in \u001b[0;36mCollection.__init__\u001b[0;34m(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, include_fields, wkt_version, allow_unsupported_drivers, **kwargs)\u001b[0m\n\u001b[1;32m 241\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmode \u001b[38;5;241m==\ [...] + "File \u001b[0;32mfiona/ogrext.pyx:588\u001b[0m, in \u001b[0;36mfiona.ogrext.Session.start\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/ogrext.pyx:143\u001b[0m, in \u001b[0;36mfiona.ogrext.gdal_open_vector\u001b[0;34m()\u001b[0m\n", + "\u001b[0;31mDriverError\u001b[0m: '/vsizip//Users/evan_1/GitHub/superset/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/tmp_geojson/ne_10m_admin_0_countries.zip' does not exist in the file system, and is not recognized as a supported dataset name." + ] + } + ], "source": [ "# Read Natural Earth data files into GeoDataFrames\n", "df_admin0_10m = gpd.read_file(f\"{data_dir}/ne_10m_admin_0_countries.zip\")\n", @@ -1295,6 +1333,52 @@ "\n", "print(\"TypeScript code written to src/countries.ts\")" ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Fb58eGlIt1LW" + }, + "source": [ + "## Clean Up" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# method to clean out our temporary geojson from the data directory\n", + "# this ensures (a) we don't commmit junk to the repo, and (b) we get fresh geojson each time we run this\n", + "def empty_directory(directory):\n", + " for filename in os.listdir(directory):\n", + " file_path = os.path.join(directory, filename)\n", + " try:\n", + " if os.path.isfile(file_path) or os.path.islink(file_path):\n", + " os.unlink(file_path)\n", + " elif os.path.isdir(file_path):\n", + " shutil.rmtree(file_path)\n", + " except Exception as e:\n", + " print(f\"Failed to delete {file_path}. Reason: {e}\")\n", + "\n", + "# do it!\n", + "empty_directory(data_dir)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -1316,7 +1400,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.5" }, "vscode": { "interpreter": {
