Skip to content

Commit

Permalink
Merge pull request #1097 from cpcloud/ts-fix
Browse files Browse the repository at this point in the history
Fix issue when converting datetimes and pandas Timestamps in an expression
  • Loading branch information
cpcloud committed May 26, 2015
2 parents 7ba4f14 + 35adee8 commit 5562599
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion blaze/compute/pyfunc.py
@@ -1,5 +1,6 @@
from __future__ import absolute_import, division, print_function

import pandas as pd
from ..expr import (Expr, Symbol, Field, Arithmetic, Math,
Date, Time, DateTime, Millisecond, Microsecond, broadcast,
sin, cos, Map, UTCFromTimestamp, DateTimeTruncate, symbol,
Expand Down Expand Up @@ -63,7 +64,7 @@ def _print_python(expr, leaves=None):

@dispatch((datetime.datetime, datetime.date))
def _print_python(expr, leaves=None):
return repr(expr), {'datetime': datetime}
return repr(expr), {'datetime': datetime, 'Timestamp': pd.Timestamp}

@dispatch(Symbol)
def _print_python(expr, leaves=None):
Expand Down
4 changes: 2 additions & 2 deletions blaze/compute/tests/test_pyfunc.py
Expand Up @@ -43,8 +43,8 @@ def test_datetime_literals_and__print_python():

def test_datetime_literals():
f = lambdify([t], t.when > '2000-01-01')
assert f((1, 0, 3, datetime.datetime(2000, 1, 2))) == True
assert f((1, 0, 3, datetime.datetime(1999, 1, 2))) == False
assert f((1, 0, 3, datetime.datetime(2000, 1, 2)))
assert not f((1, 0, 3, datetime.datetime(1999, 1, 2)))


def test_broadcast_collect():
Expand Down
3 changes: 2 additions & 1 deletion blaze/expr/arithmetic.py
Expand Up @@ -3,6 +3,7 @@
import operator
from toolz import first
import numpy as np
import pandas as pd
from datashape import dshape, var, DataShape
from dateutil.parser import parse as dt_parse
from datashape.predicates import isscalar, isboolean, isnumeric
Expand Down Expand Up @@ -220,7 +221,7 @@ def scalar_coerce(_, val):

@dispatch(ct.DateTime, _strtypes)
def scalar_coerce(_, val):
return dt_parse(val)
return pd.Timestamp(val)


@dispatch(ct.CType, _strtypes)
Expand Down
17 changes: 16 additions & 1 deletion blaze/expr/tests/test_expr.py
@@ -1,7 +1,10 @@
from __future__ import absolute_import, division, print_function

import pandas as pd

import pytest
from datashape import dshape

from datashape import dshape, var, datetime_

from blaze.expr import symbol, label, Field

Expand Down Expand Up @@ -121,3 +124,15 @@ def test_map_with_rename():
with pytest.raises(ValueError):
result.relabel(timestamp='date')
assert result.fields == ['date']


def test_hash_to_different_values():
s = symbol('s', var * datetime_)
expr = s >= pd.Timestamp('20121001')
expr2 = s >= '20121001'
assert expr2 & expr is not None
assert hash(expr) == hash(expr2)

from blaze.expr.expressions import _attr_cache
assert (expr, '_and') in _attr_cache
assert (expr2, '_and') in _attr_cache

0 comments on commit 5562599

Please sign in to comment.