Skip to content

Data types not preserved in categoricals #9350

Closed

Description

@story645

@anntzer pointed out on #9340 that the behavior for plt.plot([23, "23"]) should be two data points with identical labels. Currently it collapses them into one value:
index

Activity

  1. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Oct 10, 2017
  2. added this to the milestone on Oct 10, 2017
  3. tacaswell commented on Oct 10, 2017

    @tacaswell
    Member

    I am not super concerned about this, it is string catagoricals.

  4. efiring commented on Oct 10, 2017

    @efiring
    Member

    Which brings us back to @anntzer's earlier suggestion that we should raise an error instead of accepting this nonsensical input.

  5. anntzer commented on Oct 20, 2017

    @anntzer
    Contributor

    As an additional point where allowing uncontrolled mixing of strings and numbers can be puzzling:

    fill_between([0, 1, 2], [2, 3, 2])
    

    great, let's plot this in red

    fill_between([0, 1, 2], [2, 3, 2], "r")
    

    (saved on the same figure to save some room)
    figure_1

    Ah, that's because the second parameter is "y2" (so I needed to write color="r") and "r" got converted to "0" by the categorical converter... (I would say once an axes has used the scalar (passthrough) converter it should disable the categorical converter, just as the categorical converter should not pass scalars through.)

    I knew exactly the issue with categoricals, and that behavior still led to a bit a head scratching...

  6. story645 commented on Oct 20, 2017

    @story645
    MemberAuthor

    I agree that's a bug, but the issue seems to be that the second positional parameter is ambiguous. Like it's technically doing the correct thing, given that this works the exact same way:

    plt.fill_between([0, 1, 2], [2, 3, 2], 0)

    What I mean is

    plt.fill_between(['a', 'b', 'c'], ['e', 'f', 'g'], 'r')

    Errors out spectacularly because it tries to do a lookup on 'r' against the existing mapping and doesn't see it as a new value:

    ~/projects/matplotlib/lib/matplotlib/category.py in convert(value, unit, axis)
         47 
         48         if isinstance(value, six.string_types):
    ---> 49             return vmap[value]
         50 
         51         str_value = shim_array(value)
    
    KeyError: 'r'
    

    Also, it's not hitting the update and instead going straight to the convert, which is why this isn't working either:

    ETA: Ok, I think your point is that once I've set the yaxis to being scaler, it should have a flag of sorts that all other values passed to it need to use the same units? That seems reasonable/I agree.

  7. modified the milestones: v2.1.1, on Dec 6, 2017
  8. tacaswell commented on Feb 12, 2018

    @tacaswell
    Member

    Closed by #9783

    Still some broken edge cases (which we have tests for now).

  9. modified the milestones: , v2.2.0 on Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: categorical

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions