Skip to content
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

Pu/typing #590

Merged
merged 61 commits into from Feb 2, 2021
Merged

Pu/typing #590

merged 61 commits into from Feb 2, 2021

Conversation

izulin
Copy link
Collaborator

@izulin izulin commented Dec 28, 2020

Context

Related with #313

How has this been tested?

Types of changes

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

Related issue(s):

Checklist:

  • My code follows the code style of this project,
  • My change requires a change to the documentation,
  • I described the modification in the CHANGELOG.md file.

@izulin izulin marked this pull request as draft December 28, 2020 12:37
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Dec 28, 2020

This pull request introduces 1 alert when merging bcf1d7f into 074831e - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@codecov
Copy link

codecov bot commented Dec 28, 2020

Codecov Report

Merging #590 (2198e1d) into develop (8befe02) will decrease coverage by 0.19%.
The diff coverage is 86.60%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #590      +/-   ##
===========================================
- Coverage    92.70%   92.50%   -0.20%     
===========================================
  Files          162      163       +1     
  Lines        37840    38342     +502     
  Branches      5256     5314      +58     
===========================================
+ Hits         35078    35468     +390     
- Misses        2756     2868     +112     
  Partials         6        6              
Impacted Files Coverage Δ
src/DateTimeHelper.ts 82.50% <13.33%> (-2.38%) ⬇️
src/CellContentParser.ts 67.02% <30.95%> (-9.33%) ⬇️
src/GraphBuilder.ts 77.50% <50.00%> (+0.09%) ⬆️
src/interpreter/binarySearch.ts 74.44% <50.00%> (-10.18%) ⬇️
src/interpreter/plugin/FunctionPlugin.ts 83.75% <70.31%> (-0.52%) ⬇️
src/interpreter/ArithmeticHelper.ts 84.79% <74.83%> (-3.20%) ⬇️
src/Operations.ts 91.27% <77.77%> (+<0.01%) ⬆️
src/Config.ts 96.18% <84.00%> (-0.45%) ⬇️
src/Exporter.ts 86.44% <85.71%> (-0.23%) ⬇️
src/interpreter/SimpleRangeValue.ts 87.05% <87.05%> (ø)
... and 72 more

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Dec 28, 2020

This pull request introduces 1 alert when merging 8f481a3 into 074831e - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Dec 29, 2020

This pull request introduces 1 alert when merging 3767279 into 074831e - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@krzysztofspilka
Copy link
Member

@izulin what about is this PR?

@izulin
Copy link
Collaborator Author

izulin commented Dec 29, 2020

@izulin what about is this PR?

It is a WIP for #313

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jan 8, 2021

This pull request introduces 3 alerts when merging 782a2cf into 6870a3a - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

Copy link
Contributor

@wojciechczerniak wojciechczerniak left a comment

Choose a reason for hiding this comment

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

Sorry for the late review

  • Have you checked how types are affecting our benchmarks?
  • We call getRawValue a lot. Isn't there a single place to do that?

I will test some more later

src/interpreter/plugin/InformationPlugin.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/Config.ts Outdated
Comment on lines 68 to 75
/**
* Symbol used to denote currency numbers.
*
* @default '$'
*
* @category Number
*/
currencySymbol: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this an oversimplification? Each cell can have a different currency, especially with currency conversion functions. I'm not sure a single symbol is enough. We should have something similar to parseDate callback but with row/column so each cell can be parsed differently? I think we've discussed this before #314

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

GS accepts only one currency symbol at a given moment in the whole spreadsheet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate on that? I see more

Screenshot 2021-01-26 at 19 35 12

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I see. What do you propose then?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is tricky. Currency is different than Date (which is parsed from a string / on the editor entry). As we did it, parsing "$20" to currency from string, is different than what GS or XL does. They store some kind of metadata with the format. Value is the formula bar is unchanged numeric:

Screenshot 2021-01-27 at 09 56 54

And entered "$20" is a string. We will have incompatibility here with all the spreadsheets if we keep parsing it to CurrencyType. What we're tracking here is the number formatting, ie. date can have two different formats and they are still passed through the formula:

Screenshot 2021-01-27 at 10 04 36

What you did is great to track the Type and set the correct cell editor (number/date/text) in the Handsontable, that is what @jansiegel asked for.

Copy link
Contributor

Choose a reason for hiding this comment

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

Internally should be doable. We can save the format on CurrenctyType and DateType as an object property. And when the type is requested with API both will be available (DateType and DateType.format). This is rather an extension of what we have here.

The problem is how to set the Type and/or Format. Because all we've got is an array of simple types and no metadata: ['1', '1%', '1$', '01/01/1900', '12:00', '01/01/1900 12:00']. Guess our problem is how to get/set formats from that input. Where:

  • 1 is NumericType
  • 1% is PercentType
  • 1$ is StringType (for all spreadsheets 💣 )
  • 01/01/1900 is DateType, but... 01 01 1900, 01 Jan 1900, 01 January 1900 and others are also recognized 🙈

so there is no automatic recognition of the CurrencyType. It's a number with formatting. But take a look at the date type, it's a DateType with different formatting. I guess number, format is also tracked. Try setting scientific at A1 and then add other formats to it =A1+B1 etc. The first cell (in the formula) format is applied to the result.

Excel has a lot more info, and the CELL function is proof of that: https://support.microsoft.com/en-us/office/cell-function-51bd39a5-f338-4dbe-a33f-955d67c2b2cf with all the properties you can request for a cell.

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed and resolved in #599.

src/HyperFormula.ts Outdated Show resolved Hide resolved
Comment on lines +117 to +121
/**
* Argument should be passed with full type information.
* (e.g. Date/DateTime/Time/Currency/Percentage for numbers)
*/
passSubtype?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to mark it in function metadata? If we know that the argument has a returnNumberType set, we may assume that it should be passed as a full type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we know that the argument has a returnNumberType set, we may assume that it should be passed as a full type?

Not really. Most functions ignore input types. Some functions (usualy logical ones) use the type, e.g. IF etc.
Some other function set output type (e.g. financial).

Copy link
Contributor

Choose a reason for hiding this comment

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

So shouldn't this be up to the function to decide?
I believe it already does but based on some metadata to the Core, which may be confusing and adds to the complexity of custom functions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So shouldn't this be up to the function to decide?

Why not keep it in metadata, since it is a pretty automatic decision (you either want raw data, or rich data).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have better arguments. Metadata is fine.

src/interpreter/plugin/FunctionPlugin.ts Show resolved Hide resolved
src/interpreter/ArithmeticHelper.ts Outdated Show resolved Hide resolved
test/type-inference.spec.ts Show resolved Hide resolved
Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>
@izulin
Copy link
Collaborator Author

izulin commented Jan 18, 2021

Sorry for the late review

  • Have you checked how types are affecting our benchmarks?

@voodoo11 benchmarked

  • We call getRawValue a lot. Isn't there a single place to do that?

Not to my knowledge.

I will test some more later

izulin and others added 2 commits January 18, 2021 23:33
Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>
Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jan 18, 2021

This pull request introduces 3 alerts when merging 6c73576 into 6870a3a - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jan 19, 2021

This pull request introduces 3 alerts when merging 90091b5 into 6870a3a - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jan 22, 2021

This pull request introduces 3 alerts when merging 06fe4d8 into 6870a3a - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@wojciechczerniak
Copy link
Contributor

Sorry for the late review

  • Have you checked how types are affecting our benchmarks?

@voodoo11 benchmarked

And what are the results, any difference?

  • We call getRawValue a lot. Isn't there a single place to do that?

Not to my knowledge.

Ok

@voodoo11
Copy link
Collaborator

And what are the results, any difference?

Evaluation slowed down by 20% average, but overall build time increased only by 5% at most.

@bardek8
Copy link
Collaborator

bardek8 commented Jan 30, 2021

We can also change Known limitations file as Currency data type will be now supported (though with some limitations).

(btw also complex numbers are now supported :) )

@wojciechczerniak wojciechczerniak mentioned this pull request Jan 31, 2021
7 tasks
izulin and others added 2 commits February 1, 2021 17:42
* config

* extra val

* passes tests

* linter

* refactor

* linter

* docs

* exports

* Update src/HyperFormula.ts

Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>

* docs

* Update src/HyperFormula.ts

Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>

* refactor

* .

* bug

* linter

Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Feb 1, 2021

This pull request introduces 6 alerts when merging bdc742d into 4c318ea - view on LGTM.com

new alerts:

  • 5 for Unused variable, import, function or class
  • 1 for Useless assignment to local variable

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Feb 1, 2021

This pull request introduces 3 alerts when merging 625abcd into 4c318ea - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

Copy link
Contributor

@wojciechczerniak wojciechczerniak left a comment

Choose a reason for hiding this comment

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

Cool! I think we're good here 🏆 The documentation could be improved though:

CHANGELOG.md Outdated
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added support for row and column reordering. (#343)
- Added type inferrence for subtypes for number. (#313)
- Added parsing of number literals containing '%' or currency symbol (default '$').
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the issue/PR number

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we're not really explaining many aspects of metadata, e.g. automatic coercions of arguments. The missing part is part of runFunction wrapper, which is not mandatory for usage. The same for returnNumberType and passSubtype -- those are from runFunction wrapper.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup. We have an issue #557 to update the docs after the runFunction was introduced

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Feb 2, 2021

This pull request introduces 3 alerts when merging 2198e1d into 8befe02 - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@izulin izulin merged commit 09aead6 into develop Feb 2, 2021
@izulin izulin deleted the pu/typing branch February 2, 2021 12:25
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.

None yet

5 participants