Skip to content

Commit 1419e8e

Browse files
committed
test fixes, enhancements, and code review
1 parent 9c37b1f commit 1419e8e

File tree

19 files changed

+1092
-642
lines changed

19 files changed

+1092
-642
lines changed

doc/source/whatsnew/v0.18.0.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Highlights include:
1919

2020
- Window functions are now methods on ``.groupby`` like objects, see :ref:`here <whatsnew_0180.enhancements.moments>`.
2121
- ``pd.test()`` top-level nose test runner is available (:issue:`4327`)
22+
- Adding support for a ``RangeIndex`` as a specialized form of the ``Int64Index`` for memory savings, see :ref:`here <whatsnew_0180.enhancements.rangeindex>`.
2223

2324
Check the :ref:`API Changes <whatsnew_0180.api>` and :ref:`deprecations <whatsnew_0180.deprecations>` before updating.
2425

@@ -102,6 +103,39 @@ And multiple aggregations
102103
r.agg({'A' : ['mean','std'],
103104
'B' : ['mean','std']})
104105

106+
.. _whatsnew_0180.enhancements.rangeindex:
107+
108+
Range Index
109+
^^^^^^^^^^^
110+
111+
A ``RangeIndex`` has been added to the ``Int64Index`` sub-classes to support a memory saving alternative for common use cases. This has a similar implementation to the python ``range`` object (``xrange`` in python 2), in that it only stores the start, stop, and step values for the index. It will transparently interact with the user API, converting to ``Int64Index`` if needed.
112+
113+
This will now be the default constructed index for ``NDFrame`` objects, rather than previous an ``Int64Index``. (:issue:`939`)
114+
115+
Previous Behavior:
116+
117+
.. code-block:: python
118+
119+
In [3]: s = Series(range(1000))
120+
121+
In [4]: s.index
122+
Out[4]:
123+
Int64Index([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
124+
...
125+
990, 991, 992, 993, 994, 995, 996, 997, 998, 999], dtype='int64', length=1000)
126+
127+
In [6]: s.index.nbytes
128+
Out[6]: 8000
129+
130+
131+
New Behavior:
132+
133+
.. ipython:: python
134+
135+
s = Series(range(1000))
136+
s.index
137+
s.index.nbytes
138+
105139
.. _whatsnew_0180.enhancements.other:
106140

107141
Other enhancements

pandas/core/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from pandas.core.categorical import Categorical
99
from pandas.core.groupby import Grouper
1010
from pandas.core.format import set_eng_float_format
11-
from pandas.core.index import Index, CategoricalIndex, Int64Index, RangeIndex, Float64Index, MultiIndex
11+
from pandas.core.index import (Index, CategoricalIndex, Int64Index,
12+
RangeIndex, Float64Index, MultiIndex)
1213

1314
from pandas.core.series import Series, TimeSeries
1415
from pandas.core.frame import DataFrame

pandas/core/common.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,8 +1800,7 @@ def is_bool_indexer(key):
18001800

18011801
def _default_index(n):
18021802
from pandas.core.index import RangeIndex
1803-
result = RangeIndex(0, int(n), name=None)
1804-
return result
1803+
return RangeIndex(0, n, name=None)
18051804

18061805

18071806
def ensure_float(arr):
@@ -2200,11 +2199,6 @@ def is_integer_dtype(arr_or_dtype):
22002199
not issubclass(tipo, (np.datetime64, np.timedelta64)))
22012200

22022201

2203-
def is_int64_dtype(arr_or_dtype):
2204-
tipo = _get_dtype_type(arr_or_dtype)
2205-
return issubclass(tipo, np.int64)
2206-
2207-
22082202
def is_int_or_datetime_dtype(arr_or_dtype):
22092203
tipo = _get_dtype_type(arr_or_dtype)
22102204
return (issubclass(tipo, np.integer) or

pandas/core/dtypes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,6 @@ def __eq__(self, other):
214214
if isinstance(other, compat.string_types):
215215
return other == self.name
216216

217-
return isinstance(other, DatetimeTZDtype) and self.unit == other.unit \
218-
and self.tz == other.tz
217+
return isinstance(other, DatetimeTZDtype) and \
218+
self.unit == other.unit and \
219+
str(self.tz) == str(other.tz)

0 commit comments

Comments
 (0)