Closed martinfleis closed 8 months ago
great implementation! two small thoughts
func
over the weights. So, something like graph.apply('median')
gives you the median weight in each neighbor set. I don't mind if this looks like graph.apply(None, 'median', **kwargs)
... graph.apply('median', values=None, **kwargs)
, which matches the func
-first way that grouper.apply()
and functools.reduce()
is written? So apply func
over weights if values
are not set and otherwise ignore weights
and apply func
over values
? I am on the verge whether it can be potentially confusing or not, meaning if it should not be two methods rather than one.
I am on the verge whether it can be potentially confusing or not, meaning if it should not be two methods rather than one.
I agree on the "potentially confusing" part and think 2 distinct methods might be a good idea.
nice. two quick reactions
i think the really nice thing about the graph, especially compared to the old implementation, is how easy it is to do these kind of manipulations manually because of the way the pandas structure works underneath. An apply func is nice, but i think it would actually be more useful to demo these kinds of things in a tutorial so folks know how to actually manipulate a graph at will. You couldnt do that kinda thing with a W
couldnt this just be g._adjacency.groupby(level=0).transform(func)
? like i initially sketched for the lags?
I believe that both things are useful. Manual manipulation as well as both options of apply discussed above. I'll be reusing this code often and it is better to have a tested implementation I can just use than writing groupby from scratch every time.
You're right about the implementation though the outcome will be the same :). But I'll change that.
Actually not because y
does not have the MultiIndex assigned.
@ljwolf what about including this alongside apply
to cover your use case of applying a func
over weights?
def aggregate(self, func):
return self._adjacency.groupby(level=0).agg(func)
And we should probably also allow callable as transformation within transform
, passed to self._adjacency.groupby(level=0).transform(func)
Fine with that!
Added aggregate
and allowed callable as transformation in transform
.
It will need some examples but that applies to the rest of Graph as well :).
Closes #675