[FEA] DataFrame.query support for datetime
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.1k
- Avg merge
- 3d 6m
- Merged PRs (30d)
- 278
Description
**Is your feature request related to a problem? Please describe.**
working with `import cudf as pd`
**Describe the solution you'd like**
```
In [1]: import cudf as pd
In [2]: pd.__version__
Out[2]: '22.12.00'
In [3]: df = pd.DataFrame({'A': pd.date_range(start="2023-01-01", periods=8, freq="D")})
In [4]: df.info()
RangeIndex: 8 entries, 0 to 7
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 A 8 non-null datetime64[ns]
dtypes: datetime64[ns](1)
memory usage: 64.0 bytes
In [5]: df.query('A >= "2023-01-02"')
---------------------------------------------------------------------------
TypingError Traceback (most recent call last)
Cell In[5], line 1
----> 1 df.query('A >= "2023-01-02"')
File /usr/local/lib/python3.8/dist-packages/cudf/core/dataframe.py:4174, in DataFrame.query(self, expr, local_dict)
4168 callenv = {
4169 "locals": callframe.f_locals,
4170 "globals": callframe.f_globals,
4171 "local_dict": local_dict,
4172 }
4173 # Run query
-> 4174 boolmask = queryutils.query_execute(self, expr, callenv)
4175 return self._apply_boolean_mask(boolmask)
File /usr/local/lib/python3.8/dist-packages/cudf/utils/queryutils.py:248, in query_execute(df, expr, callenv)
246 # run kernel
247 args = [out] + colarrays + envargs
--> 248 kernel.forall(nrows)(*args)
249 out_mask = applyutils.make_aggregate_nullmask(df, columns=columns)
250 return out.set_mask(out_mask).fillna(False)
File /usr/local/lib/python3.8/dist-packages/numba/cuda/dispatcher.py:438, in ForAll.__call__(self, *args)
436 specialized = self.dispatcher
437 else:
--> 438 specialized = self.dispatcher.specialize(*args)
439 blockdim = self._compute_thread_per_block(specialized)
440 griddim = (self.ntasks + blockdim - 1) // blockdim
File /usr/local/lib/python3.8/dist-packages/numba/cuda/dispatcher.py:667, in CUDADispatcher.specialize(self, *args)
664 targetoptions = self.targetoptions
665 specialization = CUDADispatcher(self.py_func,
666 targetoptions=targetoptions)
--> 667 specialization.compile(argtypes)
668 specialization.disable_compile()
669 specialization._specialized = True
File /usr/local/lib/python3.8/dist-packages/numba/cuda/dispatcher.py:794, in CUDADispatcher.compile(self, sig)
791 if not self._can_compile:
792 raise RuntimeError("Compilation disabled")
--> 794 kernel = _Kernel(self.py_func, argtypes, **self.targetoptions)
795 # We call bind to force codegen, so that there is a cubin to cache
796 kernel.bind()
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.._acquire_compile_lock(*args, **kwargs)
32 @functools.wraps(func)
33 def _acquire_compile_lock(*args, **kwargs):
34 with self:
---> 35 return func(*args, **kwargs)
File /usr/local/lib/python3.8/dist-packages/numba/cuda/dispatcher.py:75, in _Kernel.__init__(self, py_func, argtypes, link, debug, lineinfo, inline, fastmath, extensions, max_registers, opt, device)
66 self.extensions = extensions or []
68 nvvm_options = {
69 'debug': self.debug,
70 'lineinfo': self.lineinfo,
71 'fastmath': fastmath,
72 'opt': 3 if opt else 0
73 }
---> 75 cres = compile_cuda(self.py_func, types.void, self.argtypes,
76 debug=self.debug,
77 lineinfo=self.lineinfo,
78 inline=inline,
79 fastmath=fastmath,
80 nvvm_options=nvvm_options)
81 tgt_ctx = cres.target_context
82 code = self.py_func.__code__
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.._acquire_compile_lock(*args, **kwargs)
32 @functools.wraps(func)
33 def _acquire_compile_lock(*args, **kwargs):
34 with self:
---> 35 return func(*args, **kwargs)
File /usr/local/lib/python3.8/dist-packages/numba/cuda/compiler.py:212, in compile_cuda(pyfunc, return_type, args, debug, lineinfo, inline, fastmath, nvvm_options)
210 from numba.core.target_extension import target_override
211 with target_override('cuda'):
--> 212 cres = compiler.compile_extra(typingctx=typingctx,
213 targetctx=targetctx,
214 func=pyfunc,
215 args=args,
216 return_type=return_type,
217 flags=flags,
218 locals={},
219 pipeline_class=CUDACompiler)
221 library = cres.library
222 library.finalize()
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler.py:716, in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
692 """Compiler entry point
693
694 Parameter
(...)
712 compiler pipeline
713 """
714 pipeline = pipeline_class(typingctx, targetctx, library,
715 args, return_type, flags, locals)
--> 716 return pipeline.compile_extra(func)
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler.py:452, in CompilerBase.compile_extra(self, func)
450 self.state.lifted = ()
451 self.state.lifted_from = None
--> 452 return self._compile_bytecode()
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler.py:520, in CompilerBase._compile_bytecode(self)
516 """
517 Populate and run pipeline for bytecode input
518 """
519 assert self.state.func_ir is None
--> 520 return self._compile_core()
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler.py:499, in CompilerBase._compile_core(self)
497 self.state.status.fail_reason = e
498 if is_final_pipeline:
--> 499 raise e
500 else:
501 raise CompilerError("All available pipelines exhausted")
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler.py:486, in CompilerBase._compile_core(self)
484 res = None
485 try:
--> 486 pm.run(self.state)
487 if self.state.cr is not None:
488 break
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler_machinery.py:368, in PassManager.run(self, state)
365 msg = "Failed in %s mode pipeline (step: %s)" % \
366 (self.pipeline_name, pass_desc)
367 patched_exception = self._patch_error(msg, e)
--> 368 raise patched_exception
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler_machinery.py:356, in PassManager.run(self, state)
354 pass_inst = _pass_registry.get(pss).pass_inst
355 if isinstance(pass_inst, CompilerPass):
--> 356 self._runPass(idx, pass_inst, state)
357 else:
358 raise BaseException("Legacy pass in use")
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.._acquire_compile_lock(*args, **kwargs)
32 @functools.wraps(func)
33 def _acquire_compile_lock(*args, **kwargs):
34 with self:
---> 35 return func(*args, **kwargs)
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler_machinery.py:311, in PassManager._runPass(self, index, pss, internal_state)
309 mutated |= check(pss.run_initialization, internal_state)
310 with SimpleTimer() as pass_time:
--> 311 mutated |= check(pss.run_pass, internal_state)
312 with SimpleTimer() as finalize_time:
313 mutated |= check(pss.run_finalizer, internal_state)
File /usr/local/lib/python3.8/dist-packages/numba/core/compiler_machinery.py:273, in PassManager._runPass..check(func, compiler_state)
272 def check(func, compiler_state):
--> 273 mangled = func(compiler_state)
274 if mangled not in (True, False):
275 msg = ("CompilerPass implementations should return True/False. "
276 "CompilerPass with name '%s' did not.")
File /usr/local/lib/python3.8/dist-packages/numba/core/typed_passes.py:105, in BaseTypeInference.run_pass(self, state)
99 """
100 Type inference and legalization
101 """
102 with fallback_context(state, 'Function "%s" failed type inference'
103 % (state.func_id.func_name,)):
104 # Type inference
--> 105 typemap, return_type, calltypes, errs = type_inference_stage(
106 state.typingctx,
107 state.targetctx,
108 state.func_ir,
109 state.args,
110 state.return_type,
111 state.locals,
112 raise_errors=self._raise_errors)
113 state.typemap = typemap
114 # save errors in case of partial typing
File /usr/local/lib/python3.8/dist-packages/numba/core/typed_passes.py:83, in type_inference_stage(typingctx, targetctx, interp, args, return_type, locals, raise_errors)
81 infer.build_constraint()
82 # return errors in case of partial typing
---> 83 errs = infer.propagate(raise_errors=raise_errors)
84 typemap, restype, calltypes = infer.unify(raise_errors=raise_errors)
86 # Output all Numba warnings
File /usr/local/lib/python3.8/dist-packages/numba/core/typeinfer.py:1086, in TypeInferer.propagate(self, raise_errors)
1083 force_lit_args = [e for e in errors
1084 if isinstance(e, ForceLiteralArg)]
1085 if not force_lit_args:
-> 1086 raise errors[0]
1087 else:
1088 raise reduce(operator.or_, force_lit_args)
TypingError: Failed in cuda mode pipeline (step: nopython frontend)
Failed in cuda mode pipeline (step: nopython frontend)
No implementation of function Function() found for signature:
>>> ge(datetime64[ns], Literal[str](2023-01-02))
There are 26 candidate implementations:
- Of which 24 did not match due to:
Overload of function 'ge': File: : Line N/A.
With argument(s): '(datetime64[ns], unicode_type)':
No match.
- Of which 2 did not match due to:
Operator Overload in function 'ge': File: unknown: Line unknown.
With argument(s): '(datetime64[ns], unicode_type)':
No match for registered cases:
* (bool, bool) -> bool
* (int8, int8) -> bool
* (int16, int16) -> bool
* (int32, int32) -> bool
* (int64, int64) -> bool
* (uint8, uint8) -> bool
* (uint16, uint16) -> bool
* (uint32, uint32) -> bool
* (uint64, uint64) -> bool
* (float32, float32) -> bool
* (float64, float64) -> bool
During: typing of intrinsic-call at (2)
File "", line 2:
During: resolving callee type: type(CUDADispatcher())
During: typing of call at (6)
File "", line 6:
In [6]: df.to_pandas().query('A >= "2023-01-02"')
Out[6]:
A
1 2023-01-02
2 2023-01-03
3 2023-01-04
4 2023-01-05
5 2023-01-06
6 2023-01-07
7 2023-01-08
```
Contributor guide
Assessment
This issue has not been assessed yet.