-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6547642
commit d5fbf98
Showing
5 changed files
with
241 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from monetdbe import connect, Timestamp\n", | ||
"from datetime import datetime" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"con = connect(autocommit=True) # open an in-memory database" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"cur = con.execute(\"create table example(d timestamp, i int, f float)\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"_ = cur.executemany(\"insert into example(d, i, f) values (?, ?, ?)\", (\n", | ||
" (datetime.now(), 10, 0.1),\n", | ||
" (Timestamp(2004, 2, 14, 7, 15, 0, 510241), 20, 0.2),\n", | ||
"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"_ = cur.execute(\"select * from example\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[(datetime.datetime(2020, 6, 29, 15, 40, 35, 605000), 10, 0.1),\n", | ||
" (datetime.datetime(2004, 2, 14, 7, 15, 0, 510000), 20, 0.2)]" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"cur.fetchall()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"_ = cur.execute(\"select * from example\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"array = cur.fetchdf()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 17, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(Timestamp('1970-01-01 02:24:39.017219613'),\n", | ||
" Timestamp('1817-02-23 09:10:54.898455133'))" | ||
] | ||
}, | ||
"execution_count": 17, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"tuple(array['d'])" | ||
] | ||
}, | ||
{ | ||
"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.8.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from datetime import datetime | ||
from typing import List, Any | ||
from unittest import TestCase | ||
from math import isnan | ||
from pandas import DataFrame | ||
|
||
from monetdbe import connect, Timestamp | ||
|
||
|
||
def _connect(values: List[Any], type: str) -> DataFrame: | ||
con = connect(autocommit=True) | ||
cur = con.execute(f"create table example(d {type})") | ||
cur.executemany("insert into example(d) values (?)", ((v,) for v in values)) | ||
cur.execute("select * from example") | ||
return cur.fetchdf() | ||
|
||
|
||
class TestDataFrame(TestCase): | ||
def test_timestamp(self): | ||
now = datetime.now().replace(microsecond=0) # monetdb doesn't support microseconds | ||
values = [ | ||
now, | ||
Timestamp(2004, 2, 14, 7, 15, 0, 510000), | ||
] | ||
df = _connect(values, 'timestamp') | ||
self.assertEqual(values, list(df['d'])) | ||
|
||
def test_int(self): | ||
values = [5, 10, -100] | ||
df = _connect(values, 'int') | ||
self.assertEqual(values, list(df['d'])) | ||
|
||
def test_float(self): | ||
values = [5.0, 10.0, -100.0, float('nan')] | ||
df = _connect(values, 'float') | ||
self.assertEqual(values[:-1], list(df['d'])[:-1]) | ||
self.assertTrue(isnan(df['d'].iloc[-1])) | ||
|
||
def test_char(self): | ||
values = ['a', 'i', 'é'] | ||
df = _connect(values, 'char') | ||
self.assertEqual(values, list(df['d'])) | ||
|
||
def test_string(self): | ||
values = ['asssssssssssssssss', 'iwwwwwwwwwwwwwww', 'éooooooooooooooooooooo'] | ||
df = _connect(values, 'string') | ||
self.assertEqual(values, list(df['d'])) | ||
|
||
def test_varchar(self): | ||
values = ['a', 'aa', 'éooooooooooooooooooooo'] | ||
df = _connect(values, 'string') | ||
self.assertEqual(values, list(df['d'])) | ||
|
||
def test_uuid(self): | ||
values = ['6c49869d-45dc-4b00-ae55-5bd363c0c72c', '2ad49a96-ba10-11ea-b3de-0242ac130004'] | ||
df = _connect(values, 'uuid') | ||
self.assertEqual(values, list(df['d'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters