python - PyCharm getitem warning for functions with arrays -


i'm getting code inspection warnings pycharm. understand logic, i'm not clear on appropriate way fix it. have following example function:

def get_ydata(xdata):     ydata = xdata ** 2     in range(len(ydata)):         print ydata[i] return ydata 

i 2 warnings:

>> expected type 'sized', got 'int' instead (at line 3) >> class 'int' not define '__getitem__', '[]' operator cannot used on instances (at line 4) 

the purpose of function of course parse numpy array of xdata. pycharm doesn't know that, without further indication assumes xdata (and therefore ydata) integer.

what appropriate way address warning? should note adding type checking line fix warning. optimal solution? example:

if not type(ydata) np.ndarray:     ydata = np.array(ydata) 

lastly, adding sphinx docstring information not seem have effect on warnings. (warning still sees 'int' when xdata specified str). iterating on y directly results in following error:

for y in ydata: ... >> expected 'collections.iterable', got 'int' instead 

pycharm has type hinting features may of use.

for example in case, following code makes errors go away:

import numpy np  def get_ydata(xdata):     ydata = xdata ** 2  # type: np.ndarray     in range(len(ydata)):         print(ydata[i])     return ydata 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -