{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sqlalchemy as sa\n", "import sqlite3\n", "\n", "# Show plots in Jupyter notebooks\n", "%matplotlib inline\n", "\n", "# Reload modules whenever they change\n", "# (for development purposes)\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import pandas as pd\n", "# Make clusterking package available even without installation\n", "import sys\n", "sys.path = [\"../../\"] + sys.path\n", "\n", "import json" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import clusterking as ck" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%time d = ck.Data(\"/home/kilian/tmp/scan/flavio_q2_10spoints_10bins.sql\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(\"/home/kilian/tmp/scan/flavio_q2_10spoints_10bins_data.csv\")\n", "df.set_index(\"index\", inplace=True)\n", "d.df = df\n", "with open(\"/home/kilian/tmp/scan/flavio_q2_10spoints_10bins_metadata.json\") as mdfile:\n", " md = json.load(mdfile)\n", "d.md = md\n", "d.write(\"/home/kilian/tmp/scan/flavio_q2_10spoints_10bins.sql\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.load(\"/home/kilian/Documents/19/git_sync/clusterking/clusterking/data/test/data/test.sql\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.df = pd.DataFrame({\"1\": [3, 4], \"abc\": [5, 6]})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "d.df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.load(\"test.sql\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.md[\"test\"][\"abc\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.md[\"test\"][\"abc\"] = 5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "engine = sa.create_engine('sqlite:///' + \"test.sql\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "engine.create_table(\n", " \"md\",\n", " sa.Column(\"md\", sa.PickleType())\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pickle" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nd = {1: {2: 3}}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ndpick = pickle.dumps(nd)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "conn = engine.connect()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "conn.execute(\"insert into table md values (data)\", sqlite3.Binary(ndpick))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }