0
def function1(self,*windows):
    xxx_per_win = [[] for _ in windows]

    for i in range(max(windows),self.file.shape[0]):
        for j in range(len(windows)): 
            zz = self.file['temp'][i-windows[j]:i].quantile(0.25)
            ...
            ...
            ...

o = classX(file)
windows = [3,10,20,40,80]
output = o.function1(windows)  

If I run the code above it says:

for i in range(max(windows),self.file.shape[0]):

TypeError: 'list' object cannot be interpreted as an integer

and:

zz = self.file['temp'][i-windows[j]:i].quantile(0.25)

TypeError: unsupported operand type(s) for -: 'int' and 'list'

This problem only occurs when windows is variable length (ie *windows and not just windows).

How do I fix this? What is causing this?

11
  • 1
    when you run only the function definition no error will be raised, can you provide a minimal example code that calls the function to throw an error? the issue is clearly with the format of the input data which is not shown. Commented Dec 10, 2019 at 21:00
  • 1
    How do you call the method ? Commented Dec 10, 2019 at 21:00
  • What are some example values for the windows variable? Commented Dec 10, 2019 at 21:04
  • @azro any better? Commented Dec 10, 2019 at 21:07
  • @TadhgMcDonald-Jensen any better? Commented Dec 10, 2019 at 21:07

1 Answer 1

2

The max function expects to be passed multiple arguments, not a tuple containing multiple arguments. Your windows variable is a tuple.

So, not:

for i in range(max(windows),self.file.shape[0]):

Do this instead:

for i in range(max(*windows),self.file.shape[0]):

On your second error, involving the line:

zz = self.file['temp'][i-windows[j]:i].quantile(0.25)
# TypeError: unsupported operand type(s) for -: 'int' and 'list'

Ok, you are subtracting, and it's complaining that you can't subtract a list from an integer. And since I have no idea what windows[j] contains, I can't say whether there's a list in there or not.. but if there is, there can't be. You haven't given us a working example to try.

What I suggest you do is to put some debugging output in your code, eg:

print('i=%s, j=%s, windows[j]=%s' % (i, j, windows[j]))

and thus see what your data looks like.

Sign up to request clarification or add additional context in comments.

2 Comments

this fixes the first issue. sorry originally forgot to put the second (related) issue in the question
What are you passing to the function?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.