@@ -599,52 +599,68 @@ ndarray, you can always convert explicitly using ``np.asarray(idx.hour)``.
599
599
pd.unique will now be consistent with extension types
600
600
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
601
601
602
- 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`)
602
+ 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.
603
603
604
- Previous behaviour:
604
+ - Datetime tz-aware
605
605
606
- Datetime tz-aware
606
+ Previous behaviour:
607
607
608
- .. code-block:: ipython
608
+ .. code-block:: ipython
609
609
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)
610
+ # Series
611
+ In [5]: Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
612
+ pd.Timestamp('20160101', tz='US/Eastern')])).unique()
613
+ Out[5]: array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object)
613
614
614
- In [7 ]: pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
615
- pd.Timestamp('20160101', tz='US/Eastern')])))
616
- Out[7 ]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
615
+ In [6 ]: pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
616
+ pd.Timestamp('20160101', tz='US/Eastern')])))
617
+ Out[6 ]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
617
618
618
- Categoricals
619
+ # Index
620
+ In [7]: pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
621
+ pd.Timestamp('20160101', tz='US/Eastern')]).unique()
622
+ Out[7]: DatetimeIndex(['2016-01-01 00:00:00-05:00'], dtype='datetime64[ns, US/Eastern]', freq=None)
619
623
620
- .. code-block:: ipython
624
+ In [8]: pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
625
+ pd.Timestamp('20160101', tz='US/Eastern')]))
626
+ Out[8]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
621
627
628
+ New Behavior:
622
629
623
- In [1]: pd.Series(pd.Categorical(list('aabc'))).unique()
624
- Out[1]:
625
- [a, b, c]
626
- Categories (3, object): [a, b, c]
630
+ .. ipython:: python
627
631
628
- In [2]: pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
629
- Out[2]: array(['a', 'b', 'c'], dtype=object)
632
+ # Series
633
+ Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
634
+ pd.Timestamp('20160101', tz='US/Eastern')])).unique()
635
+ pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
636
+ pd.Timestamp('20160101', tz='US/Eastern')])))
630
637
631
- New Behavior:
638
+ # Index
639
+ pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
640
+ pd.Timestamp('20160101', tz='US/Eastern')])
641
+ pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
642
+ pd.Timestamp('20160101', tz='US/Eastern')]))
632
643
633
- Datetime tz-aware
644
+ - Categoricals
634
645
635
- .. ipython:: python
646
+ Previous behaviour:
647
+
648
+ .. code-block:: ipython
636
649
637
- Series( pd.Index([ pd.Timestamp('20160101', tz='US/Eastern'),
638
- pd.Timestamp('20160101', tz='US/Eastern')])).unique()
639
- pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
640
- pd.Timestamp('20160101', tz='US/Eastern')])))
650
+ In [1]: pd.Series( pd.Categorical(list('aabc'))).unique()
651
+ Out[1]:
652
+ [a, b, c]
653
+ Categories (3, object): [a, b, c]
641
654
642
- Categoricals
655
+ In [2]: pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
656
+ Out[2]: array(['a', 'b', 'c'], dtype=object)
643
657
644
- .. ipython:: python
658
+ New Behavior:
659
+
660
+ .. ipython:: python
645
661
646
- pd.Series(pd.Categorical(list('aabc'))).unique()
647
- pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
662
+ pd.Series(pd.Categorical(list('aabc'))).unique()
663
+ pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
648
664
649
665
.. _whatsnew_0200.api_breaking.s3:
650
666
0 commit comments