Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Conversation

@frauzufall
Copy link
Member

@frauzufall frauzufall commented May 10, 2020

This PR is addressing scijava/scijava-table#22 and making the DefaultTableIOPlugin compatible with the latest scijava-table version.

Changes:

  • fix tests to test default behaviour & API options instead of changing parameters via reflection
  • read and write row and column headers by default
  • DefaultTableIOPlugin extends TableIOPlugin
  • removed the plugin parameters, making use of TableIOOptions instead
  • guess column types based on first data row

…nore misbehaving tests #5

* the new testParser test demonstrates how a table containing Double
values are saved to disk by default and loaded as String values by
default after opening the same file
* testSmallTables and testQuote had to be ignored since they modify the
parameters of DefaultTableIOPlugin and that messes with the new
testParser test since they share a context
@frauzufall frauzufall marked this pull request as ready for review July 6, 2020 13:12
@frauzufall frauzufall requested a review from imagejan July 6, 2020 13:12
@imagejan imagejan self-requested a review July 7, 2020 19:34
Copy link
Member

@imagejan imagejan left a comment

Choose a reason for hiding this comment

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

Thanks @frauzufall, I think this PR is almost good to be merged. There are just a few minor changes I'd like to see:

  • remove commented code (DISCUSS)
  • remove setValues in DefaultTableIOPluginTest (line 314-327)

We can also improve test coverage by adding:

  • tests opening files with varying row length (throwing IOException -- or maybe ignoring it as an option?)
  • test guessParser for Integer, Long and Float in addition to Double
  • test save(Table, String) signature
  • test a few more invalid/error cases

But I guess these things can wait for a later pull request.

* opting against guessing whether row and / or column headers exist in favor
of predictable and deterministic behavior
@frauzufall
Copy link
Member Author

frauzufall commented Jul 25, 2020

Thanks for the comments @imagejan!

About testing guessParser for Long and Float: I'm not sure how to do this right and I'm also not sure if the guessParser method works as expected there.

This test fails, because the String can and therefore will be interpreted as Integer:

assertEquals(3L, DefaultTableIOPlugin.guessParser("3L").apply("3L"));

Using a number too big for an Integer should work, I thought, but this also fails and I don't understand why:

assertEquals(36564573745634564L, DefaultTableIOPlugin.guessParser("36564573745634564L").apply("36564573745634564L"));

Here is the result:

java.lang.AssertionError: 
Expected :36564573745634564
Actual   :36564573745634564L

Similar problem with Float vs Double. Maybe I'm missing something very basic about how numbers are represented.

@imagejan
Copy link
Member

@frauzufall wrote:

assertEquals(36564573745634564L, DefaultTableIOPlugin.guessParser("36564573745634564L").apply("36564573745634564L"));

36564573745634564L will be interpreted as a String because of the trailing L, no?

I added a slightly modified line:

assertEquals(36564573745634564L, DefaultTableIOPlugin.guessParser("36564573745634564").apply("36564573745634564"));

... and it passes.


However, we now still have dead code with the Float.valueOf, as this one will never be reached because any decimal number can be interpreted by Double.valueOf here:

try {
Double.valueOf(content);
return Double::valueOf;
} catch(NumberFormatException ignored) {}
try {
Float.valueOf(content);
return Float::valueOf;
} catch(NumberFormatException ignored) {}

* the guessParser method is currently always prefers double over float
* the float parsing lines are therefore removed since they can't be
reached
@frauzufall
Copy link
Member Author

@imagejan Thanks! I removed the dead code. It will just always use double when guessing, that's fine, right? I'm sure the guessing can be further improved, but we probably need to release a new version of this repo too before uploading the most recent version of scijava-table to Fiji..

@imagejan imagejan merged commit 25b056d into master Aug 3, 2020
@imagejan imagejan deleted the improve-tests branch August 3, 2020 09:19
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.

3 participants