Skip to content

Update groupbyclass.py - #434

Merged
reuster986 merged 7 commits into
masterfrom
mhmerrill-groupby-patch
Jul 20, 2020
Merged

reuster986 merged 7 commits into
masterfrom
mhmerrill-groupby-patch

Conversation

@mhmerrill

@mhmerrill mhmerrill commented Jul 17, 2020 •

Copy link
Copy Markdown
Contributor

fixes #432
take care of out of scope object refs (h1 and h2) from the Strings case which were not alive and deleted before the server operation started
original code is here https://github.com/mhmerrill/arkouda/blob/b75031c3c2e219d550588dd6fe9bb76fbaef1623/arkouda/groupbyclass.py#L104-L125

take care of out of scope object refs from Strings case which were not alive during server operation
fixed syntax error
@mhmerrill
mhmerrill requested a review from reuster986 July 17, 2020 17:10
reenable groupby test case which was skipped before because of sporatic failure
file skipna default from False to True on aggregate
@mhmerrill

mhmerrill commented Jul 17, 2020 •

Copy link
Copy Markdown
Contributor Author

I flipped the default value for skipna on GroupBy.aggregate from False to True I believe that this now matches the pandas default behavior which fixes the test failure we were seeing. That said, @reuster986 can np.random.randn(N) generate either very large, very small, NaN, or INF values? could this have contributed to the test failure because we didn't have skipna before and after we got it until today it was set to False. We have had several (4) groupby_test pass in a row now

@mhmerrill
mhmerrill requested a review from ronawho July 17, 2020 23:36
Comment thread tests/groupby_test.py

# https://github.com/mhmerrill/arkouda/issues/365
@unittest.skip
#@unittest.skip

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still fails for me ~1/20 trials. There's probably a one-liner for this, but I'm just testing with:

#!/usr/bin/env bash

for run in {1..100}; do
  python3 -m pytest tests/groupby_test.py
  if [ $? -ne 0 ]; then
    exit 1
  fi
done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ronawho can you look for a message on the failure which looks like:
Different values (abs diff = nan)
this is what is printed when the answers don't match between pandas and arkouda.
which reduction is failing? Is it always the same one?
for me it was:

Doing aggregate(int64, prod)
Different values (abs diff = nan)

I ran your script and failed after 15 successes

@ronawho ronawho Jul 18, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me where the actual failure occurs, but I do see:

Doing aggregate(int64, prod)
Different values (abs diff = nan)

I updated my script to just print failures to a file:

for run in {1..100}; do
  python3 -m pytest tests/groupby_test.py &> out.txt
  if [ $? -ne 0 ]; then
    cat out.txt >> failures.txt
    echo "Failure"
  fi
done

And here's the log for 4 failures: failures.txt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reuster986 it occurred to me that the log(0) is undefined, what if zero is sneaking into the computation. That would produce NaN wouldn't it. Maybe the algorithm here takes care of this but I keep seeing NaN from the check routine in the test.

@mhmerrill mhmerrill Jul 20, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reuster986 I was going to put an issue in to cover this and decouple the logic fix from this PR so we would not delay these changes. Unless you are going to get the logic change done and tested... today or tomorrow.
if you want I would like you to check your changes into this branch, so they go in with this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running the 100-fold test right now. Assuming it passes, I can check the changes into this branch.

@bmcdonald3 bmcdonald3 Jul 20, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems we did not implement skipna for the segmented product reduction. Or for segmented argmin or argmax

@mhmerrill Yes, that is correct, we only implemented skipna for min, max, sum, and mean. Would you like it to be extended to those operations as well? The reason we only went with those 4 is that the original intent for skipna was motivated by Roland's use, which only required the use of those 4, but I think it makes sense to have it implemented for all of them if you want that done as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcdobe100 The code I'm testing right now includes skipna for prod. Since I was writing code for handling zeros, it was relatively easy to do the same for NaNs at the same time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I discovered a bug in pandas. When doing groupby followed by .aggregate('prod'), pandas will sometimes compute a nan when the product should be zero. I discovered this by manually generating a dataframe with int64 columns, doing a groupby-aggregate with prod, and finding a group with nan product. Then, I manually sliced out the group from the original dataframe and computed the true product, which was 0.

I believe the pandas bug is the root cause of the intermittent test failures. In the latest commit, I modified groupby_test.py to replace nan with 0 in the pandas prod result, and I ran the 100-fold test with no failures.

@reuster986

Copy link
Copy Markdown
Collaborator

Ok, I think this PR is ready to go.

@reuster986
reuster986 merged commit e6ee080 into master Jul 20, 2020
@mhmerrill
mhmerrill deleted the mhmerrill-groupby-patch branch July 21, 2020 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GroupBy on strings fails with unkown symbol error

4 participants