Skip to content

Array.reindex fails if adding labels of different type #909

Open

Description

@gdementen
>>> arr = ndtest("year=2020..2022")
>>> arr.reindex("year", [2020, 2022])
year  2020  2022
       0.0   2.0
>>> arr.reindex("year", [2020, "a", 2022, "b"])
ValueError: incompatible axes:
Axis([], 'year')
vs
Axis([], 'year')

Bonus point for the totally cryptic error message 😉

Activity

  1. gdementen commented on Jan 25, 2021

    @gdementen
    ContributorAuthor

    As a workaround in this case, we can change the axis type to string then use strings to reindex then rechange the labels but that's kinda awful:

    >>> arr.set_labels("year", str).reindex("year", ["2020", "a", "2022", "b"]).set_labels("year", {"2020": 2020, "2022": 2022})
    year  2020    a  2022    b
           0.0  nan   2.0  nan
  2. added this to the 0.34 milestone on Jul 30, 2021
  3. gdementen commented on Oct 4, 2021

    @gdementen
    ContributorAuthor

    related to #910

  4. modified the milestones: 0.34, 0.35 on Sep 13, 2022
  5. modified the milestones: 0.35, 0.36 on Sep 11, 2023
  6. modified the milestones: 0.36, 0.35 on Oct 8, 2024
  7. gdementen commented on Oct 8, 2024

    @gdementen
    ContributorAuthor

    With recent versions of larray (at least 0.34.6), this now silently returns a bad result, instead of the cryptic error message, which is much worse, so I just bumped priority.

    >>> arr = ndtest("year=2020..2022")
    >>> res = arr.reindex("year", [2020, "a", 2022, "b"])
    >>> res
    year  2020    a  2022    b
           nan  nan   nan  nan
    >>> res.info
    4
     year [4]: '2020' 'a' '2022' 'b'
    dtype: float64
    memory used: 32 bytes
  8. modified the milestones: 0.35, 0.36 on Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions