最近,当我在jupyter笔记本中运行此python代码时,我陷入了导入“ timezonefinder”模块的困境:
import timezonefinder
发生以下异常:
NotImplementedError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\numba\targets\base.py in get_constant_generic(self, builder, ty, val)
498 try:
--> 499 impl = self._get_constants.find((ty,))
500 return impl(self, builder, ty, val)
C:\ProgramData\Anaconda3\lib\site-packages\numba\targets\base.py in find(self, sig)
49 if out is None:
---> 50 out = self._find(sig)
51 self._cache[sig] = out
C:\ProgramData\Anaconda3\lib\site-packages\numba\targets\base.py in _find(self, sig)
58 else:
---> 59 raise NotImplementedError(self, sig)
60
NotImplementedError: (<numba.targets.base.OverloadSelector object at 0x0000020A10A2B0F0>, (readonly bytes(uint8, 1d, C),))
During handling of the above exception, another exception occurred:
NotImplementedError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\numba\errors.py in new_error_context(fmt_, *args, **kwargs)
616 try:
--> 617 yield
618 except NumbaError as e:
C:\ProgramData\Anaconda3\lib\site-packages\numba\lowering.py in lower_block(self, block)
258 loc=self.loc, errcls_=defaulterrcls):
--> 259 self.lower_inst(inst)
260
C:\ProgramData\Anaconda3\lib\site-packages\numba\lowering.py in lower_inst(self, inst)
307 ty = self.typeof(inst.target.name)
--> 308 val = self.lower_assign(ty, inst)
309 self.storevar(val, inst.target.name)
C:\ProgramData\Anaconda3\lib\site-packages\numba\lowering.py in lower_assign(self, ty, inst)
448 res = self.context.get_constant_generic(self.builder, ty,
--> 449 value.value)
450 self.incref(ty, res)
C:\ProgramData\Anaconda3\lib\site-packages\numba\targets\base.py in get_constant_generic(self, builder, ty, val)
501 except NotImplementedError:
--> 502 raise NotImplementedError("Cannot lower constant of type '%s'" % (ty,))
503
NotImplementedError: Cannot lower constant of type 'readonly bytes(uint8, 1d, C)'
During handling of the above exception, another exception occurred:
LoweringError Traceback (most recent call last)
<ipython-input-19-34c219114d8a> in <module>()
----> 1 import timezonefinder
C:\ProgramData\Anaconda3\lib\site-packages\timezonefinder\__init__.py in <module>()
1 from __future__ import absolute_import, division, print_function, unicode_literals
2
----> 3 from .timezonefinder import TimezoneFinder
4
5 __version__ = '3.4.2'
C:\ProgramData\Anaconda3\lib\site-packages\timezonefinder\timezonefinder.py in <module>()
20 try:
21 import numba
---> 22 from .helpers_numba import coord2int, distance_to_polygon_exact, distance_to_polygon, inside_polygon, \
23 all_the_same, rectify_coordinates, coord2shortcut, convert2coord_pairs, convert2coords
24 except ImportError:
C:\ProgramData\Anaconda3\lib\site-packages\timezonefinder\helpers_numba.py in <module>()
307
308 # @cc.export('rectify_coordinates', dtype_2float_tuple(f8, f8))
--> 309 @njit(dtype_2float_tuple(f8, f8), cache=True)
310 def rectify_coordinates(lng, lat):
311 if lng > 180.0 or lng < -180.0 or lat > 90.0 or lat < -90.0:
C:\ProgramData\Anaconda3\lib\site-packages\numba\decorators.py in wrapper(func)
181 with typeinfer.register_dispatcher(disp):
182 for sig in sigs:
--> 183 disp.compile(sig)
184 disp.disable_compile()
185 return disp
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler_lock.py in _acquire_compile_lock(*args, **kwargs)
30 def _acquire_compile_lock(*args, **kwargs):
31 with self:
---> 32 return func(*args, **kwargs)
33 return _acquire_compile_lock
34
C:\ProgramData\Anaconda3\lib\site-packages\numba\dispatcher.py in compile(self, sig)
653
654 self._cache_misses[sig] += 1
--> 655 cres = self._compiler.compile(args, return_type)
656 self.add_overload(cres)
657 self._cache.save_overload(sig, cres)
C:\ProgramData\Anaconda3\lib\site-packages\numba\dispatcher.py in compile(self, args, return_type)
80 args=args, return_type=return_type,
81 flags=flags, locals=self.locals,
---> 82 pipeline_class=self.pipeline_class)
83 # Check typing error if object mode is used
84 if cres.typing_error is not None and not flags.enable_pyobject:
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
924 pipeline = pipeline_class(typingctx, targetctx, library,
925 args, return_type, flags, locals)
--> 926 return pipeline.compile_extra(func)
927
928
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in compile_extra(self, func)
372 self.lifted = ()
373 self.lifted_from = None
--> 374 return self._compile_bytecode()
375
376 def compile_ir(self, func_ir, lifted=(), lifted_from=None):
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in _compile_bytecode(self)
855 """
856 assert self.func_ir is None
--> 857 return self._compile_core()
858
859 def _compile_ir(self):
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in _compile_core(self)
842 self.define_pipelines(pm)
843 pm.finalize()
--> 844 res = pm.run(self.status)
845 if res is not None:
846 # Early pipeline completion
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler_lock.py in _acquire_compile_lock(*args, **kwargs)
30 def _acquire_compile_lock(*args, **kwargs):
31 with self:
---> 32 return func(*args, **kwargs)
33 return _acquire_compile_lock
34
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in run(self, status)
253 # No more fallback pipelines?
254 if is_final_pipeline:
--> 255 raise patched_exception
256 # Go to next fallback pipeline
257 else:
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in run(self, status)
244 try:
245 event(stage_name)
--> 246 stage()
247 except _EarlyPipelineCompletion as e:
248 return e.result
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in stage_nopython_backend(self)
715 """
716 lowerfn = self.backend_nopython_mode
--> 717 self._backend(lowerfn, objectmode=False)
718
719 def stage_compile_interp_mode(self):
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in _backend(self, lowerfn, objectmode)
664 self.library.enable_object_caching()
665
--> 666 lowered = lowerfn()
667 signature = typing.signature(self.return_type, *self.args)
668 self.cr = compile_result(
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in backend_nopython_mode(self)
651 self.calltypes,
652 self.flags,
--> 653 self.metadata)
654
655 def _backend(self, lowerfn, objectmode):
C:\ProgramData\Anaconda3\lib\site-packages\numba\compiler.py in native_lowering_stage(targetctx, library, interp, typemap, restype, calltypes, flags, metadata)
1046 lower = lowering.Lower(targetctx, library, fndesc, interp,
1047 metadata=metadata)
-> 1048 lower.lower()
1049 if not flags.no_cpython_wrapper:
1050 lower.create_cpython_wrapper(flags.release_gil)
C:\ProgramData\Anaconda3\lib\site-packages\numba\lowering.py in lower(self)
176 if self.generator_info is None:
177 self.genlower = None
--> 178 self.lower_normal_function(self.fndesc)
179 else:
180 self.genlower = self.GeneratorLower(self)
C:\ProgramData\Anaconda3\lib\site-packages\numba\lowering.py in lower_normal_function(self, fndesc)
217 # Init argument values
218 self.extract_function_arguments()
--> 219 entry_block_tail = self.lower_function_body()
220
221 # Close tail of entry block
C:\ProgramData\Anaconda3\lib\site-packages\numba\lowering.py in lower_function_body(self)
242 bb = self.blkmap[offset]
243 self.builder.position_at_end(bb)
--> 244 self.lower_block(block)
245
246 self.post_lower()
C:\ProgramData\Anaconda3\lib\site-packages\numba\lowering.py in lower_block(self, block)
257 with new_error_context('lowering "{inst}" at {loc}', inst=inst,
258 loc=self.loc, errcls_=defaulterrcls):
--> 259 self.lower_inst(inst)
260
261 def create_cpython_wrapper(self, release_gil=False):
C:\ProgramData\Anaconda3\lib\contextlib.py in __exit__(self, type, value, traceback)
128 value = type()
129 try:
--> 130 self.gen.throw(type, value, traceback)
131 except StopIteration as exc:
132 # Suppress StopIteration *unless* it's the same exception that
C:\ProgramData\Anaconda3\lib\site-packages\numba\errors.py in new_error_context(fmt_, *args, **kwargs)
623 from numba import config
624 tb = sys.exc_info()[2] if config.FULL_TRACEBACKS else None
--> 625 six.reraise(type(newerr), newerr, tb)
626
627
C:\ProgramData\Anaconda3\lib\site-packages\numba\six.py in reraise(tp, value, tb)
657 if value.__traceback__ is not tb:
658 raise value.with_traceback(tb)
--> 659 raise value
660
661 else:
LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
Cannot lower constant of type 'readonly bytes(uint8, 1d, C)'
File "C:\ProgramData\Anaconda3\lib\site-packages\timezonefinder\helpers_numba.py", line 312:
def rectify_coordinates(lng, lat):
<source elided>
if lng > 180.0 or lng < -180.0 or lat > 90.0 or lat < -90.0:
raise ValueError(b'The coordinates should be given in degrees. They are out ouf bounds.')
^
[1] During: lowering "$const32.2 = const(bytes, b'The coordinates should be given in degrees. They are out ouf bounds.')" at C:\ProgramData\Anaconda3\lib\site-packages\timezonefinder\helpers_numba.py (312)
我到目前为止尝试过的解决方案:
那么,有人知道如何解决这个问题吗?谢谢你一百万。
答案 0 :(得分:0)
可能是因为numba不支持timezonefinder。您可以检查supported python features。
关于timezonefinder的信息尚不清楚,因此,numba支持的功能的参考为numba。
看看overloading with numba是否有重载(使用“您无法控制的第三方库,并且您希望为该库中的特定功能提供Numba兼容的实现”)