The E402 rule should permit cell magics as well as comments before the import statements. The cell magics must come first.
e.g.
%%time
import expensive_module
I suspect that line magics should also be permitted before import statements, like:
%time import expensive_module
import cheap_module
Error message is:
E402 Module level import not at top of cell