Skip to content

Commit

Permalink
TRIAD_DEFAULT_TIMESTAMP (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Han Wang committed May 20, 2020
1 parent 1e69353 commit e49b11c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ A collection of python utility functions for Fugue projects
```
pip install triad
```


## Release History
### 0.3.2
* extracted TRIAD_DEFAULT_TIMESTAMP as a constant

### <=0.3.1
* Open sourced and docs are ready
* Added basic utility functions
* Types and schema are based on pyarrow
* A better indexed and ordered dict
* Added ParamDict
9 changes: 5 additions & 4 deletions tests/utils/test_pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
schemas_equal,
to_pa_datatype,
validate_column_name,
TRIAD_DEFAULT_TIMESTAMP
)


Expand Down Expand Up @@ -55,19 +56,19 @@ def test_expression_conversion():

def test__parse_type():
assert pa.int32() == _parse_type(" int ")
assert pa.timestamp("ns") == _parse_type(" datetime ")
assert TRIAD_DEFAULT_TIMESTAMP == _parse_type(" datetime ")
assert pa.timestamp("s", "America/New_York") == _parse_type(
" timestamp ( s , America/New_York ) "
)
assert pa.timestamp("s") == _parse_type(" timestamp ( s ) ")
assert _parse_type(" timestamp ( ns ) ") == _parse_type(" datetime ")
assert _parse_type(" timestamp ( us ) ") == _parse_type(" datetime ")
assert pa.decimal128(5, 2) == _parse_type(" decimal(5,2) ")
assert pa.decimal128(5) == _parse_type(" decimal ( 5 ) ")


def test__type_to_expression():
assert "int" == _type_to_expression(pa.int32())
assert "datetime" == _type_to_expression(pa.timestamp("ns"))
assert "datetime" == _type_to_expression(TRIAD_DEFAULT_TIMESTAMP)
assert "timestamp(ns,America/New_York)" == _type_to_expression(
pa.timestamp("ns", "America/New_York")
)
Expand All @@ -83,7 +84,7 @@ def test_to_pa_datatype():
assert pa.int64() == to_pa_datatype(int)
assert pa.float64() == to_pa_datatype(float)
assert pa.float64() == to_pa_datatype(np.float64)
assert pa.timestamp("ns") == to_pa_datatype(datetime)
assert TRIAD_DEFAULT_TIMESTAMP == to_pa_datatype(datetime)
assert pa.date32() == to_pa_datatype(date)
assert pa.date32() == to_pa_datatype("date")
raises(TypeError, lambda: to_pa_datatype(123))
Expand Down
2 changes: 1 addition & 1 deletion triad/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.1"
__version__ = "0.3.2"
8 changes: 5 additions & 3 deletions triad/utils/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from triad.utils.json import loads_no_dup
from triad.utils.string import validate_triad_var_name

TRIAD_DEFAULT_TIMESTAMP = pa.timestamp("us")

_TYPE_EXPRESSION_MAPPING: Dict[str, pa.DataType] = {
"null": pa.null(),
"str": pa.string(),
Expand Down Expand Up @@ -39,7 +41,7 @@
"double": pa.float64(),
"float64": pa.float64(),
"date": pa.date32(),
"datetime": pa.timestamp("ns"),
"datetime": TRIAD_DEFAULT_TIMESTAMP,
}

_TYPE_EXPRESSION_R_MAPPING: Dict[pa.DataType, str] = {
Expand All @@ -58,7 +60,7 @@
pa.float32(): "float",
pa.float64(): "double",
pa.date32(): "date",
pa.timestamp("ns"): "datetime",
TRIAD_DEFAULT_TIMESTAMP: "datetime",
}


Expand Down Expand Up @@ -129,7 +131,7 @@ def to_pa_datatype(obj: Any) -> pa.DataType:
if isinstance(obj, str):
return _parse_type(obj)
if issubclass(obj, datetime):
return pa.timestamp("ns")
return TRIAD_DEFAULT_TIMESTAMP
if issubclass(obj, date):
return pa.date32()
return pa.from_numpy_dtype(np.dtype(obj))
Expand Down

0 comments on commit e49b11c

Please sign in to comment.