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

Incorrect documentation for null values conversion in to-number expression. #7083

Closed
sharkinsspatial opened this issue Aug 6, 2018 · 4 comments
Labels

Comments

@sharkinsspatial
Copy link

mapbox-gl-js version: 0.47.0

browser: Chrome 67.0.3396.87

Steps to Trigger Behavior

  1. Apply filter expression to a source where the property used in the get expression does not exist for the feature.
  2. Use a to-number expression to convert the null value to 0.

Link to Demonstration

jsFiddle (please open devTools to see relevant console warnings).

Expected Behavior

Non-existent property value should be converted to 0 as described in the to-number documentation.

Actual Behavior

A console warning Could not convert null to number. is created.

I am using this approach in filter expressions as described in this issue. It also appears that the existing tests contradict the to-number null value handling described in the documentation.

@jfirebaugh
Copy link
Contributor

Good catch. I'm not sure whether the documentation or implementation is in error. /cc @anandthakker

@anandthakker
Copy link
Contributor

Ah. Yeah, IIRC the documentation states our original intent, and I still think that makes sense.

@Sillson
Copy link

Sillson commented Mar 15, 2023

Question about the behavior if someone has a moment to answer --

If the the "to-number" function returns 0 from null, doesn't this conflict with parsing a string of '0'? Fore example, if I'm hoping to conditionally style in the following way:

'paint': {
      'circle-color': [
        'case',
          ['all', [">=", ["to-number", ["get", "value"]], 0], ["<", ["to-number", ["get", "value"]], 100]], '#fff',
          ['all', [">=", ["to-number", ["get", "value"]], 100], ["<", ["to-number", ["get", "value"]], 500]], '#000',
          "#2f2f2f"
      ]
    },

This means both my null and '0' values return 0.

@dhaq
Copy link

dhaq commented Jun 15, 2023

Did you resolved this issues on iOS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants