Skip to content

Fix diffing empty DataTables #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

botandrose
Copy link
Contributor

@botandrose botandrose commented Mar 27, 2017

Summary

Fixes the following:

DataTable.from([[]]).diff! [[]] #=> NoMethodError: undefined method `length' for nil:NilClass

See #1096 for much more details.

Details

Added a private #ensure_2d method to DataTable, and used it internally in #pad_and_match to make sure we're always dealing with an array of arrays, which the code had previously been assuming.

Motivation and Context

Fixes #1096

How Has This Been Tested?

Added unit test to expose bug, then wrote patch to fix it.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I've added tests for my code
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Copy link
Contributor

@oscaralanpierce oscaralanpierce left a comment

Choose a reason for hiding this comment

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

@botandrose Let me know what you think of the changes I suggested, if you disagree we can talk about it.

return ensure_2d(cols.transpose), ensure_2d((matched_cols + unmatched_cols).transpose)
end

def ensure_2d(array) #:nodoc:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should make this method private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already protected... is that good enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yeah, that's great. I didn't see that.

t1 = DataTable.from([[]])
t2 = DataTable.from([[]])
t1.diff!(t2)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use something like

expect{ t1.diff!(t2) }.not_to raise_error

would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically redundant, but more explicitly conveys the intent. I like! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, if you could just change that and push it up I'll merge :) Thanks!

@botandrose botandrose force-pushed the fix_diffing_empty_datatables branch from ae1c759 to cc61811 Compare March 29, 2017 21:40
@botandrose
Copy link
Contributor Author

Okay! Pushed, and all 💚 here. Thank you for your time and attention!

I'll be submitting fixes for one or two more DataTable-related bugs over the coming days, BTW.

@oscaralanpierce
Copy link
Contributor

Thank you @botandrose - we really appreciate your help with the project!

@oscaralanpierce oscaralanpierce merged commit e4bfc5f into cucumber:master Mar 29, 2017
@botandrose botandrose deleted the fix_diffing_empty_datatables branch March 29, 2017 22:06
@mattwynne
Copy link
Member

Thanks for handling it @danascheider 👌

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diffing empty DataTables crashes with a nil error
4 participants