← 输入框|github.com|刷新
Skip to content

Bad rendering of VersionInfo in Pandas DataFrame #87

Closed

Description

@s-celles

Hello,

I noticed that VersionInfo are rendered badly in Pandas DataFrame.
(see s-celles/arduino_libraries_search#8 )

They are rendered as tuple.

In [1]: import pandas as pd
In [2]: import semver
In [3]: versions = ['4.0.0', '5.0.0', '5.0.1', '10.0.0']
In [4]: df = pd.DataFrame(versions, columns=['versions'])
In [5]: df  # version as string
In [6]: df.sort_values(by='versions')  # so they are not ordered correctly
Out[6]:
  versions
3   10.0.0
0    4.0.0
1    5.0.0
2    5.0.1
In [7]: df['versions'] = df['versions'].map(semver.parse_version_info)  # parse versions as `VersionInfo`
In [8]: df.sort_values(by='versions')  # VersionInfo are ordered correctly but are badly rendered
Out[8]:
                 versions
0   (4, 0, 0, None, None)
1   (5, 0, 0, None, None)
2   (5, 0, 1, None, None)
3  (10, 0, 0, None, None)

I don't know what method Pandas use for rendering them.
What I see is that it's neither using __str__ neither using __repr__ method

In [9]: v = df['versions'].iloc[-1]

In [10]: v
Out[10]: VersionInfo(major=10, minor=0, patch=0, prerelease=None, build=None)

In [11]: v.__str__()
Out[11]: '10.0.0'

In [12]: v.__repr__()
Out[12]: 'VersionInfo(major=10, minor=0, patch=0, prerelease=None, build=None)'

VersionInfo inherits from namedtuple so this is probably related.

Any idea?

Activity

  1. s-celles commented on May 25, 2018

    @s-celles
    MemberAuthor

    Issue opened upstream at pandas-dev/pandas#21208

  2. added a commit that references this issue on May 26, 2018
    2754b7e
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

    No labels
    No labels

    Type

    No type

    Fields

    SIze

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions