@@ -598,52 +598,68 @@ ndarray, you can always convert explicitly using ``np.asarray(idx.hour)``.
598598pd.unique will now be consistent with extension types
599599^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
600600
601- In prior versions, using ``Series.unique()`` and ``pd.unique(Series)`` on ``Categorical`` and tz-aware datatypes would yield different return types. These are now consistent to return the extension type. Note that the behavior of ``Index.unique()`` and ``pd.unique(Index)`` has not changed. (:issue:`15939`)
601+ In prior versions, using ``Series.unique()`` and ``pd.unique(Series)`` on ``Categorical`` and tz-aware datatypes would yield different return types. These are now consistent to return the extension type.
602602
603- Previous behaviour:
603+ - Datetime tz-aware
604604
605- Datetime tz-aware
605+ Previous behaviour:
606606
607- .. code-block:: ipython
607+ .. code-block:: ipython
608608
609- In [5]: Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
610- pd.Timestamp('20160101', tz='US/Eastern')])).unique()
611- Out[5]: array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object)
609+ # Series
610+ In [5]: Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
611+ pd.Timestamp('20160101', tz='US/Eastern')])).unique()
612+ Out[5]: array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object)
612613
613- In [7 ]: pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
614- pd.Timestamp('20160101', tz='US/Eastern')])))
615- Out[7 ]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
614+ In [6 ]: pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
615+ pd.Timestamp('20160101', tz='US/Eastern')])))
616+ Out[6 ]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
616617
617- Categoricals
618+ # Index
619+ In [7]: pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
620+ pd.Timestamp('20160101', tz='US/Eastern')]).unique()
621+ Out[7]: DatetimeIndex(['2016-01-01 00:00:00-05:00'], dtype='datetime64[ns, US/Eastern]', freq=None)
618622
619- .. code-block:: ipython
623+ In [8]: pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
624+ pd.Timestamp('20160101', tz='US/Eastern')]))
625+ Out[8]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
620626
627+ New Behavior:
621628
622- In [1]: pd.Series(pd.Categorical(list('aabc'))).unique()
623- Out[1]:
624- [a, b, c]
625- Categories (3, object): [a, b, c]
629+ .. ipython:: python
626630
627- In [2]: pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
628- Out[2]: array(['a', 'b', 'c'], dtype=object)
631+ # Series
632+ Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
633+ pd.Timestamp('20160101', tz='US/Eastern')])).unique()
634+ pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
635+ pd.Timestamp('20160101', tz='US/Eastern')])))
629636
630- New Behavior:
637+ # Index
638+ pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
639+ pd.Timestamp('20160101', tz='US/Eastern')])
640+ pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
641+ pd.Timestamp('20160101', tz='US/Eastern')]))
631642
632- Datetime tz-aware
643+ - Categoricals
633644
634- .. ipython:: python
645+ Previous behaviour:
646+
647+ .. code-block:: ipython
635648
636- Series( pd.Index([ pd.Timestamp('20160101', tz='US/Eastern'),
637- pd.Timestamp('20160101', tz='US/Eastern')])).unique()
638- pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
639- pd.Timestamp('20160101', tz='US/Eastern')])))
649+ In [1]: pd.Series( pd.Categorical(list('aabc'))).unique()
650+ Out[1]:
651+ [a, b, c]
652+ Categories (3, object): [a, b, c]
640653
641- Categoricals
654+ In [2]: pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
655+ Out[2]: array(['a', 'b', 'c'], dtype=object)
642656
643- .. ipython:: python
657+ New Behavior:
658+
659+ .. ipython:: python
644660
645- pd.Series(pd.Categorical(list('aabc'))).unique()
646- pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
661+ pd.Series(pd.Categorical(list('aabc'))).unique()
662+ pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
647663
648664.. _whatsnew_0200.api_breaking.s3:
649665
0 commit comments