@@ -598,52 +598,68 @@ ndarray, you can always convert explicitly using ``np.asarray(idx.hour)``.
598
598
pd.unique will now be consistent with extension types
599
599
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
600
600
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.
602
602
603
- Previous behaviour:
603
+ - Datetime tz-aware
604
604
605
- Datetime tz-aware
605
+ Previous behaviour:
606
606
607
- .. code-block:: ipython
607
+ .. code-block:: ipython
608
608
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)
612
613
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]')
616
617
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)
618
622
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]')
620
626
627
+ New Behavior:
621
628
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
626
630
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')])))
629
636
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')]))
631
642
632
- Datetime tz-aware
643
+ - Categoricals
633
644
634
- .. ipython:: python
645
+ Previous behaviour:
646
+
647
+ .. code-block:: ipython
635
648
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]
640
653
641
- Categoricals
654
+ In [2]: pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
655
+ Out[2]: array(['a', 'b', 'c'], dtype=object)
642
656
643
- .. ipython:: python
657
+ New Behavior:
658
+
659
+ .. ipython:: python
644
660
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())
647
663
648
664
.. _whatsnew_0200.api_breaking.s3:
649
665
0 commit comments