-
Notifications
You must be signed in to change notification settings - Fork 145
Jk/subtotal #536
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
Jk/subtotal #536
Conversation
Co-authored-by: Jakub Kowalski <[email protected]>
wojciechczerniak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add to https://github.com/handsontable/hyperformula/blob/master/docs/guide/known-limitations.md that SUBTOTAL is not supported fully. There is no difference between 1 and 101. We don't have support for row/column visibility meta data. @izulin @voodoo11 is this even possible? A callback in options maybe?
hfInstance = new Hyperformula({
isHidden: function(rowIndex) {
return handsontableInstance.isHidden(rowIndex);
}
});| expect(engine.getCellValue(adr('A1'))).toBeCloseTo(0.707106781186548, 6) | ||
| expect(engine.getCellValue(adr('A2'))).toBeCloseTo(1.78885438199983, 6) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike the STDEV function includes values of type Text and Logical. Text values are treated as number 0. Logical TRUE is treated as 1, and FALSE is treated as 0. Empty cells are not included.
The handling of string constants as parameters is implementation-defined. Either, string constants are converted to numbers, if possible and otherwise, they are treated as 0, or string constants are always treated as 0.
🙈 Which implementation did we choose? How does it relate to Excel requirements?
- Arguments can be the following: numbers; names, arrays, or references that contain numbers; text representations of numbers; or logical values, such as TRUE and FALSE, in a reference.
- Arguments that contain TRUE evaluate as 1; arguments that contain text or FALSE evaluate as 0 (zero).
- If an argument is an array or reference, only values in that array or reference are used. Empty cells and text values in the array or reference are ignored.
- Arguments that are error values or text that cannot be translated into numbers cause errors.
- If you do not want to include logical values and text representations of numbers in a reference as part of the calculation, use the STDEV function.
BTW We should add more tests for the requirements above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which implementation did we choose? How does it relate to Excel requirements?
I don't really understand -- we implemented STDEVA function.
The logic behind -A variants are nothing new, we already handled it with AVERAGEA, MAXA, MINA, SUMA functions. I'll add more extensive test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ODFF description suggests that STDEV can have different behavior depending on the implementation: "The handling of string constants as parameters is implementation-defined. Either, string constants are converted to numbers, if possible and otherwise, they are treated as 0, or string constants are always treated as 0."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Then for consistency I would keep it the same as in AVERAGEA. Where should it be documented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would create a test that is our behaviour documentation with a clear description and an inconsistency comment
That would be super messy with the logic behind triggering recalculations, caching etc. (if done correctly, would probably result in performance hit). |
bardek8
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes!
LGTM, but let's wait for a green light from @wojciechczerniak
wojciechczerniak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added few examples but all tests should be reviewed if they can be improved.
| it('should calculate variance (sample)', () => { | ||
| const engine = HyperFormula.buildFromArray([ | ||
| ['=VAR.S(2, 3)'], | ||
| ['=VAR.S(2, 3, 4, TRUE(), FALSE(), "1",)'], | ||
| ['=VAR.S(B3:I3)', 2, 3, 4, true, false, 'a', '\'1', null], | ||
| ]) | ||
| expect(engine.getCellValue(adr('A1'))).toEqual(0.5) | ||
| expect(engine.getCellValue(adr('A2'))).toBeCloseTo(2.28571428571429, 6) //inconsistency with product #1 | ||
| expect(engine.getCellValue(adr('A3'))).toEqual(1) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add clear descriptions to the conditions we're checking
it('should ignore empty cells, logical values, text and error values if argument is a reference', () => {
['=VAR.S(B3:I3)', 2, 3, 4, true, false, 'a', '\'1', null, '#DIV/0'],
it('should count logical values and text representation of numbers that are arguments', () => {
['=VAR.S(2, 3, 4, TRUE(), FALSE(), "1",)'],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors are not ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistency with the docs then? Not again...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is it in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Empty cells, logical values, text, or error values in the array or reference are ignored." Source: https://support.microsoft.com/en-us/office/var-s-function-913633de-136b-449d-813e-65a00b2b990b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the implementation clearly propagates errors 🥇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, nothing to add here then 🤷 Thanks for checking
wojciechczerniak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Few descriptions can be more specific though. They say the same but results are different. I've added specifics to two of them but could you apply those to all pairs?
STDEVA vs STDEVS
STDEVPA vs STDEVP
VARA vs VARS
VARPA vs VARP
Co-authored-by: Wojciech Czerniak <[email protected]>
Co-authored-by: Wojciech Czerniak <[email protected]>
Co-authored-by: Wojciech Czerniak <[email protected]>
Co-authored-by: Wojciech Czerniak <[email protected]>
Co-authored-by: Wojciech Czerniak <[email protected]>
| 'VAR.S': { | ||
| method: 'vars', | ||
| }, | ||
| 'VAR.P': { | ||
| method: 'varp', | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be a valid solution to make VARP and VARS aliases here that are linking to the same method but under different name?
| 'VAR.S': { | |
| method: 'vars', | |
| }, | |
| 'VAR.P': { | |
| method: 'varp', | |
| }, | |
| 'VAR.S': { | |
| method: 'vars', | |
| }, | |
| 'VAR.P': { | |
| method: 'varp', | |
| }, | |
| 'VARS': { | |
| method: 'vars', | |
| }, | |
| 'VARP': { | |
| method: 'varp', | |
| }, |
BTW. Are we missing arguments definitions or they are redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those functions are not using the mechanism that requires args definitions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no such method as 'VARS' -- VAR should be an alias of VAR.S
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wojciechczerniak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! 🥇
Context
14 new functions: VAR.P, VAR.S, VARA, VARPA, STDEV.P, STDEV.S, STDEVA, STDEVPA, SUBTOTAL, PRODUCT, VARP, VAR, STDEVP, STDEV.
How has this been tested?
Types of changes
Related issue(s):
Checklist: