-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: evaluate datetime ops in python with eval #4924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
maybe add some tests where use is comparing a date column with a non-date as an aside in future min/max/diff/shift on dates have to be done in python land |
@@ -493,8 +495,14 @@ def _possibly_evaluate_binop(self, op, op_class, lhs, rhs, | |||
maybe_eval_in_python=('==', '!=')): | |||
res = op(lhs, rhs) | |||
|
|||
# "in"/"not in" ops are always evaluated in python | |||
if (res.op in _cmp_ops_syms and | |||
lhs.kind in _date_kinds or lhs.kind in _date_kinds): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should be rhs
this should eventually handle timedelta as well |
under 1.7! they r like ints so I bet ne can handle them but prob better to handle in python because of NaT |
i ithink i'll do a new pr for that |
💥
|
return pd.Timestamp(self._value) | ||
elif kind == 'timestamp': | ||
return self._value.asm8.view('i8') | ||
return np.datetime64(self._value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you setting the kind somewhere? I woldn't do this, instead Timestamp(self._value).value if you really need the i8 value. why would these need to be i8 anyhow? are they evaluated in python space? (for which you are calling functions)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually getting the i8
value. That's what I was doing previously, to evaluate datetime ops using numexpr
. kind
is just a string repr of either the class name or the dtype, it's a computed property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok....I just wouldn't allow a datetime time at all (instead just wrap Timestamp around it)....makes consistent
@jreback comments? |
@@ -1898,6 +1898,7 @@ def _get_index_resolvers(self, axis): | |||
# index or columns | |||
axis_index = getattr(self, axis) | |||
d = dict() | |||
prefix = axis[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the future maybe this function should be in core/generic?
looks fine otherwise |
moved to generic and added a smoke test for failing panel/panel4d with multiiindex |
slight hit when using |
turns out it's because a |
bombs away |
ENH: evaluate datetime ops in python with eval
@cpcloud do you recall if we fixed this for timedelta ops as well (which should be evaluated in python space and not by numexpr) |
Don't think there's a test for them in top level query/eval, but there are some tests in |
closes #4897
Also adds
DatetimeIndex
comparisons in query expressions and a corresponding vbench for a simpleTimestamp
vs eitherSeries
orDatetimeIndex
.