# What does \`groupby\` use to determine equality?

**URL:** <https://discourse.julialang.org/t/what-does-groupby-use-to-determine-equality/20106>\
**Category:** Data\
**Tags:** dataframes\
**Created:** [January 25, 2019, 7:15pm UTC](https://discourse.julialang.org/t/what-does-groupby-use-to-determine-equality/20106 "2019-01-25T19:15:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [January 25, 2019, 7:15pm UTC](https://discourse.julialang.org/t/what-does-groupby-use-to-determine-equality/20106/1 "2019-01-25T19:15:09Z")

</div>

I have a dataframe with some custom types in one of the columns I’d like to `groupby`. This doesn’t seem to work correctly as the `groupby` seems to consider objects that are `==` and have identical `hash` to be distinct. What function does `groupby` use to decide whether elements are distinct?

I’m sure I’ll find it in the source code eventually, but haven’t so far…

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 25, 2019, 7:23pm UTC](https://discourse.julialang.org/t/what-does-groupby-use-to-determine-equality/20106/2 "2019-01-25T19:23:50Z")

</div>

Is uses `hash` and `isequal`. Do you have an example?

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [January 25, 2019, 7:30pm UTC](https://discourse.julialang.org/t/what-does-groupby-use-to-determine-equality/20106/3 "2019-01-25T19:30:27Z")

</div>

That’s what I thought… hmm, this is really weird, I did a little hack where I grouped by a column of `hash` instead and that works fine… sounds like those should be equivalent. Might be a bug, I’ll try to get a MWE when I get a chance, thanks.

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [January 26, 2019, 1:39pm UTC](https://discourse.julialang.org/t/what-does-groupby-use-to-determine-equality/20106/4 "2019-01-26T13:39:30Z")

</div>

Did you try reindexing by the columns you wish to groupby first?
