Questions tagged [functools]

functools is a module for the Python language which provides support for working with higher-order functions: functions that act on or return other functions

functools is a module for the Python language which provides support for working with higher-order functions: functions that act on or return other functions.

The official documentation can be found here: here

382 questions
0
votes
0 answers

how python pass two dataframe as argument into one function with the function tools partial?

When pass two dataframe obj into the func.It goes right. While using partial, it says: TypeError: fall() got multiple values for argument 'dfn' Here is the test code? Any one knows why? from functools import partial from multiprocessing import Pool…
WilsonF
  • 85
  • 6
0
votes
1 answer

how to tell if a partial has all arguments satisfied

if I'm building a function call using partial, is there any way to query the partial to see if all the arguments for that function have been supplied? For instance in the code below is there any function I can pass empty_partial, partial_partial,…
MetaStack
  • 3,266
  • 4
  • 30
  • 67
0
votes
1 answer

Numpy add outer, string change?

I have a dataframe df1= HPE FRE UNE 0 S0 S0 S0 1 S1 S1 S1 using the below code("reduce" is a functool function, sta is a list containing the columns of df1): reduce(lambda x,y:np.add.outer(x,y),sta).reshape(-1) I reduced my dataframe to…
Bhanu Tez
  • 296
  • 2
  • 14
0
votes
1 answer

Dataproc: functools.partial no attribute '__module__' error for pyspark UDF

I am using GCP/Dataproc for some spark/graphframe calculations. In my private spark/hadoop standalone cluster, I have no issue using functools.partial when defining pysparkUDF. But, now with GCP/Dataproc, I have an issue as below. Here are some…
0
votes
0 answers

jupyter kernel failing with following error: 'module' object has no attribute 'partial'

I am having trouble running a kernel in jupyter notebook $ conda info active environment : None user config file : /home/jazzy/.condarc populated config files : conda version : 4.5.4 conda-build version : not installed …
jagan
  • 45
  • 7
0
votes
2 answers

Parallelizing a function with multiple lists arguments with python's multiprocessing

I hope this isn't a duplicate, but I couldn't find a fully satisfying answer for this specific problem. Given a function with multiple list arguments and one iterable, e.g. here with two lists def function(list1, list2, iterable): i1 =…
mmarah
  • 83
  • 9
0
votes
0 answers

How to combine decorators?

I would like the logger to print the linenumber where the subprocess.run method is called, the example below prints the linenumber where the wrapfunction is defined #!/usr/bin/env python3 import logging, sys, functools, subprocess …
v217
  • 765
  • 1
  • 6
  • 17
0
votes
3 answers

Anonymous function managing function's outputs, without lambda

Say I have a function that returns a tuple of outputs: def f(): return 'zero', 1 But I have to supply in-line a new anonymous function that returns only e.g. the zeroth element of that returned tuple. This is an easy one-liner with a…
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
0
votes
1 answer

Best way to make data loaded in main() an implicit argument of a function in Python

My main function loads a largish dataframe from a csv supplied by the user (along with several other data objects), and then instantiates an object that forms a bunch of equations as part of a mathematical programming problem. Many of the equations'…
GrayOnGray
  • 315
  • 3
  • 12
0
votes
2 answers

Using functools.partial to make custom filters for pdfquery getting attribute error

Background I'm using pdfquery to parse multiple files like this one. Problem I'm trying to write a generalized filer function, building off of the custom selectors mentioned in pdfquery's docs, that can take a specific range as an argument. Because…
James Draper
  • 5,110
  • 5
  • 40
  • 59
0
votes
2 answers

How to use the functools.partial on a function which has an argument which is a callable?

I'm trying to use the function partial from module functools on a callable which has an argument which is a function. I've come up with a minimalist sample code. from functools import partial def g(f, x): return f(x) def cube(x): return…
stackoverflower
  • 301
  • 4
  • 14
0
votes
1 answer

pyqt connect to functools.partail passes signal value

I am having some trouble passing arguments to a function using functools.partial() when connecting it to a GUI Qt signal (log_this() is a dummy function just to convey the…
Ido A
  • 87
  • 1
  • 1
  • 8
0
votes
0 answers

Creating a tree structure with a logging dictionary

I have a DF that I'd like to create a tree structure with. My spreadsheet looks like this: Regional Exposure.750013 | Not Classified.18500016 | Country Exposure (Equity).750015 | Country Exposure (Equity) to Yugoslavia.18750254 Regional…
Window
  • 87
  • 1
  • 8
0
votes
1 answer

Hashlib MemoryError in Python 3.5 but not in 2.7

I've been porting a set of Python 2.7 scripts to Python 3.5 so that I can use some libraries that aren't available in 2.7, but I'm getting MemoryError from this code that worked previously: import hashlib, functools sha2h = hashlib.sha256() with…
0
votes
0 answers

f() with functools.partial to do a groupby with multiple parameters

I need to decide whether a row of stock-quotes meet certain criteria. For this I use the function 'Trade_signal_calc' to test if MACD (one col in df) is positive (first if). Then if 'MACD' passes the 'MACDsig' (another col from df) from below…
Excaliburst
  • 143
  • 1
  • 4
  • 15