@@ -568,52 +568,68 @@ ndarray, you can always convert explicitly using ``np.asarray(idx.hour)``.
568
568
pd.unique will now be consistent with extension types
569
569
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
570
570
571
- 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`)
571
+ 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.
572
572
573
- Previous behaviour:
573
+ - Datetime tz-aware
574
574
575
- Datetime tz-aware
575
+ Previous behaviour:
576
576
577
- .. code-block:: ipython
577
+ .. code-block:: ipython
578
578
579
- In [5]: Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
580
- pd.Timestamp('20160101', tz='US/Eastern')])).unique()
581
- Out[5]: array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object)
579
+ # Series
580
+ In [5]: Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
581
+ pd.Timestamp('20160101', tz='US/Eastern')])).unique()
582
+ Out[5]: array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object)
582
583
583
- In [7 ]: pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
584
- pd.Timestamp('20160101', tz='US/Eastern')])))
585
- Out[7 ]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
584
+ In [6 ]: pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
585
+ pd.Timestamp('20160101', tz='US/Eastern')])))
586
+ Out[6 ]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
586
587
587
- Categoricals
588
+ # Index
589
+ In [7]: pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
590
+ pd.Timestamp('20160101', tz='US/Eastern')]).unique()
591
+ Out[7]: DatetimeIndex(['2016-01-01 00:00:00-05:00'], dtype='datetime64[ns, US/Eastern]', freq=None)
588
592
589
- .. code-block:: ipython
593
+ In [8]: pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
594
+ pd.Timestamp('20160101', tz='US/Eastern')]))
595
+ Out[8]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
590
596
597
+ New Behavior:
591
598
592
- In [1]: pd.Series(pd.Categorical(list('aabc'))).unique()
593
- Out[1]:
594
- [a, b, c]
595
- Categories (3, object): [a, b, c]
599
+ .. ipython:: python
596
600
597
- In [2]: pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
598
- Out[2]: array(['a', 'b', 'c'], dtype=object)
601
+ # Series
602
+ Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
603
+ pd.Timestamp('20160101', tz='US/Eastern')])).unique()
604
+ pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
605
+ pd.Timestamp('20160101', tz='US/Eastern')])))
599
606
600
- New Behavior:
607
+ # Index
608
+ pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
609
+ pd.Timestamp('20160101', tz='US/Eastern')])
610
+ pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
611
+ pd.Timestamp('20160101', tz='US/Eastern')]))
601
612
602
- Datetime tz-aware
613
+ - Categoricals
603
614
604
- .. ipython:: python
615
+ Previous behaviour:
616
+
617
+ .. code-block:: ipython
605
618
606
- Series( pd.Index([ pd.Timestamp('20160101', tz='US/Eastern'),
607
- pd.Timestamp('20160101', tz='US/Eastern')])).unique()
608
- pd.unique(Series(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
609
- pd.Timestamp('20160101', tz='US/Eastern')])))
619
+ In [1]: pd.Series( pd.Categorical(list('aabc'))).unique()
620
+ Out[1]:
621
+ [a, b, c]
622
+ Categories (3, object): [a, b, c]
610
623
611
- Categoricals
624
+ In [2]: pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
625
+ Out[2]: array(['a', 'b', 'c'], dtype=object)
612
626
613
- .. ipython:: python
627
+ New Behavior:
628
+
629
+ .. ipython:: python
614
630
615
- pd.Series(pd.Categorical(list('aabc'))).unique()
616
- pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
631
+ pd.Series(pd.Categorical(list('aabc'))).unique()
632
+ pd.unique(pd.Series(pd.Categorical(list('aabc'))).unique())
617
633
618
634
.. _whatsnew_0200.api_breaking.s3:
619
635
0 commit comments