dataframegointerfacegota

Modify a default value in the Stringer interface in go


I'm looking at the print interface in the gota dataframe here: https://github.com/kniren/gota/blob/master/dataframe/dataframe.go#L99

I see the default value is shortCols = true, given here.

When I call the print data frame, how can I override this value to print with shortCols = false when I println?

fmt.Println(fil)

eg, I'd like to print all columns, rather than just the first 5 as the above produces the below:

[31x16] DataFrame

    valA   valB    valC    valD    valE        ...
 0:  578   8.30     491    7959    1.040000    ...
 1:  577   8.30     291    7975    2.050000    ...
 2:  466   16.7     179    6470    3.210000    ...
 3:  592   9.03     194    8212    4.040000    ...

Solution

  • Without modifying the library there is nothing you can do.

    If modifying the library is an option you have a few possibilities:

    1. Change the name of the internal formatting function so it is exported and call that. This is a bit more work, since you need to explicitly call a function every time you want to print a DataFrame, but it is a reasonable option if you want to make minimal changes to the way the library works.

      Basically change print to Print on lines 101 and 104 (I think those are the only occurrences of that function; if not the compiler will be happy to point out the others :P)

    2. Change the arguments to df.print in the definition of df.String. This is positively trivial, but it has the effect of changing the default behaviour, which may or may not be a good thing.

      For this option just change line 101 to return df.print(true, false, true, true, 10, 70, "DataFrame") or whatever combination fits your needs.

    3. Add a new method for each printing format you want, and explicitly call these new methods. This is more work than #1 or #2, but some people may prefer it.

    Personally, I would go with #1, but your question makes #2 sound more like what you want.