Pycharm Removing Swifter Import Upon Optimising Import

My pycharm automatically reformats the code and optimises the imports (meaning, it also removes unused imports) on top a .py file, a feature which I like. But a wrinkle is I am using the swifter library with pandas, which I need to import, but do not have to use directly, as in 

#!/usr/bin/env python3
# encoding: utf-8
import pandas as pd
import swifter # This line disappears after saving
....
df:pd.DataFrame
df['some_col'].swifter.apply(...) # Intended use. Does not work without the swifter import

When I save the above code, the faithful import optimiser removes the swifter import statement. So how to get the benefit of optimised imports while making an exception for swifter? 

 

0

Hello, 

Disabling "Optimize imports" on save should do the trick

0

Antonina Belianskaya thanks, that occurred to me as well. But then I will lose the optimisation on all my library imports. I was wondering if there is any kind of noinspection statement that will give me a more granular control, so as to not remove that import only. 

# noinspection Import
0

Yes, you are right: 

import swifter # noqa

will do the trick. 

0

请先登录再写评论。