Skip to content

COMPAT: .unique() should be type preserving #15442

Closed
@jreback

Description

@jreback

xref https://github.com/pandas-dev/pandas/pull/15439/files#r101811209

In [1]: Series([1, 2, 2], dtype='int8').unique()
Out[1]: array([1, 2])

In [3]: Series([1, 2, 2], dtype='int32').unique()
Out[3]: array([1, 2])

In [4]: Series([1, 2, 2], dtype='int64').unique()
Out[4]: array([1, 2])

In [5]: Series([1, 2, 2], dtype='float32').unique()
Out[5]: array([ 1.,  2.])

these should all be the original dtype.

We only create hashtables (and use them in unique) for int64, float64 and uint64, should do this for other dtypes.
https://github.com/pandas-dev/pandas/blob/master/pandas/src/hashtable_class_helper.pxi.in#L222

I thought there was an issue about this, but guess not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions