Ilya Schurov's Avatar

Ilya Schurov

@ilyaschurov.bsky.social

Mathematics, AI, ML, education and applications. http://ilya.schurov.com/

131 Followers  |  570 Following  |  6 Posts  |  Joined: 11.11.2023  |  1.53

Latest posts by ilyaschurov.bsky.social on Bluesky

Hi Jan-Willem, thanks, could you add me?

20.11.2024 15:24 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

Similarly, I can dump results of the indermediate step to a file, with a helper function like this:

def dump(filename):
def wrapper(df):
df.to_parquet(filename)
return df
return wrapper

And so on! If you didn't use .pipe before, give it a try, it's nice!

20.11.2024 11:28 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

Now I wrote a small helper function

def assrt(condition):
def wrapper(df):
assert condition(df)
return df
return wrapper

and use this function with a .pipe method:

df.assign(…).query(…).pipe(assrt(lambda _: not _['column'].isna().any())).groupby(…)…

20.11.2024 11:28 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0

Assume I want to make sure that at some intermediate step I do not have NaNs in a column, and give an error otherwise. Previously, I would break the method chain, assign that intermediate result to a variable, add an assert on that variable, and then continue the chain. Not nice.

20.11.2024 11:28 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0

I like pandas method chaining and my code usually looks like this:

df.assign(…).query(…).groupby(…)[['some', 'var']].sum().sort_values(…).iloc[:10].mean()

The problem with this approach is that it is not easy to get access to the results of intermediate steps. Recently I stumbled upon a solution!

20.11.2024 11:28 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0

Hi there! I am a mathematician, ML researcher and educator, currently working at Radboud University, Nijmegen, The Netherlands. Applying ML and some mathematical stuff to condenced matter physics (Neural Quantum States and friends). I also teach Scientific Computing at Constructor University, Bremen

20.11.2024 11:07 β€” πŸ‘ 4    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

@ilyaschurov is following 19 prominent accounts