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

index on number type differentiates between integer and decimal notation #6526

Closed
sanderr opened this issue Sep 19, 2023 · 2 comments · Fixed by inmanta/std#468 or inmanta/std#472
Closed
Assignees
Labels
bug Something isn't working compiler
Milestone

Comments

@sanderr
Copy link
Contributor

sanderr commented Sep 19, 2023

Actionables

ISO7 only!

  • make number behave like float: make an explicit decimal point required for the number type. The number(x) cast should be verified to work so it can be used to assign int values to number types.
  • create the float alias for number because it more clearly conveys what it means. Update documentation to use float rather than number.
  • verify that lsm and inmanta-lsm can work with this new float type

Motivation

An index on an attribute of type number only considers a number expressed respectively with and without .0 to be diffferent, while these are just different representations of the same number. As an example, the following model prints False.

entity A:
    number x
end

implement A using std::none

index A(x)


std::print(A(x=0) == A(x=0.0))
@sanderr sanderr added bug Something isn't working compiler labels Sep 19, 2023
@sanderr sanderr changed the title index on number type differentiates between int and float index on number type differentiates between integer and decimal notation Sep 19, 2023
@sanderr
Copy link
Contributor Author

sanderr commented Sep 19, 2023

Indexes seem to be built using repr, which comes across as very brittle to me:

attributes = {k: repr(v.get_value()) for (k, v) in instance.slots.items() if v.is_ready()}

@sanderr
Copy link
Contributor Author

sanderr commented Sep 19, 2023

Discussed in planning meeting:

  • make number behave like float:̶ m̶a̶k̶e̶ ̶a̶n̶ ̶e̶x̶p̶l̶i̶c̶i̶t̶ ̶d̶e̶c̶i̶m̶a̶l̶ ̶p̶o̶i̶n̶t̶ ̶r̶e̶q̶u̶i̶r̶e̶d̶ ̶f̶o̶r̶ ̶t̶h̶e̶ ̶n̶u̶m̶b̶e̶r̶ ̶t̶y̶p̶e̶. The number(x) cast should be verified to work so it can be used to assign int values to number types.
  • create the float alias for number because it more clearly conveys what it means. Update documentation to use float rather than number.
  • add testcases: description: should work + index lookup on float with int should work

@FloLey FloLey self-assigned this Oct 23, 2023
@FloLey FloLey reopened this Oct 27, 2023
@FloLey FloLey reopened this Oct 30, 2023
arnaudsjs added a commit that referenced this issue Nov 23, 2023
…d decimal notation when used in indexes. (Issue #6526, PR #6686)"

This reverts commit e026d74.
@FloLey FloLey reopened this Nov 23, 2023
@sanderr sanderr added this to the iso7 milestone Nov 28, 2023
FloLey added a commit that referenced this issue Dec 2, 2023
…l notation when used in indexes. (Issue #6526, PR #6772)

# Description

1. create the float type which is like a float in python. Update documentation to mention number will be deprecated

2. add testcases for following scenario and fix it

```
entity A:
    float x
end

implement A using std::none

index A(x)

std::print(A(x=0) == A(x=0.0))
```
This will still not work with the number type

3. index lookup on float with int should work

closes #6526

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [x] Attached issue to pull request
- [x] Changelog entry
- [x] Type annotations are present
- [x] Code is clear and sufficiently documented
- [x] No (preventable) type errors (check using make mypy or make mypy-diff)
- [x] Sufficient test cases (reproduces the bug/tests the requested feature)
- [x] Correct, in line with design
- [x] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
- [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
inmantaci pushed a commit that referenced this issue Dec 4, 2023
…l notation when used in indexes. (Issue #6526, PR #6800)

…l notation when used in indexes. (Issue #6526, PR #6772)

# Description

1. create the float type which is like a float in python. Update documentation to mention number will be deprecated

2. add testcases for following scenario and fix it

```
entity A:
    float x
end

implement A using std::none

index A(x)

std::print(A(x=0) == A(x=0.0))
```
This will still not work with the number type

3. index lookup on float with int should work

closes #6526

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [x] Attached issue to pull request
- [x] Changelog entry
- [x] Type annotations are present
- [x] Code is clear and sufficiently documented
- [x] No (preventable) type errors (check using make mypy or make mypy-diff)
- [x] Sufficient test cases (reproduces the bug/tests the requested feature)
- [x] Correct, in line with design
- [x] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
- [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment