Loosing Type help when passing a structure to an imported function

Using pandas to create a dataframe in Main. In Main, dataframe. shows a intelligent auto-complete with 10's of options all related to dataframe.

dataframe = pd.read_csv(root_folder + file_in, header=0)
processfile(dataframe)

Then, when passed to processfile (a from-import) , the dataframe. intelligent help shows 9 every generic auto-complete options.

def processfile(dataframe):
print(dataframe)
dataframe.

I assume the function has no awareness of the object type and PyCharm is reverting to language standard methods.   How do I get the imported function to know that dataframe is a pandas.DataFrame?  And enable the use of intelligent help.

1
2 comments

You can do this using type hints:

import pandas

def processfile(dataframe: pandas.DataFrame):
print(dataframe)
dataframe.<caret> # Shows pandas completions
0

Perfect.  Thank you!  New to Python and not familiar with type hints.  Form seems similar to Typescript.  Google and Stack Exchange examples of parameter passing did not show this.  Working Great!

0

Please sign in to leave a comment.