Skip to content

Commit 157f1ad

Browse files
committed
test fixes, enhancements, and code review
1 parent d9b9a02 commit 157f1ad

19 files changed

+1197
-730
lines changed

doc/source/whatsnew/v0.18.0.txt

+34
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

+2-1
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

+27-24
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,34 @@ def _check(cls, inst):
7676

7777

7878
ABCIndex = create_pandas_abc_type("ABCIndex", "_typ", ("index",))
79-
ABCInt64Index = create_pandas_abc_type("ABCInt64Index", "_typ", ("int64index",))
80-
ABCFloat64Index = create_pandas_abc_type("ABCFloat64Index", "_typ", ("float64index",))
81-
ABCMultiIndex = create_pandas_abc_type("ABCMultiIndex", "_typ", ("multiindex",))
82-
ABCDatetimeIndex = create_pandas_abc_type("ABCDatetimeIndex", "_typ", ("datetimeindex",))
83-
ABCTimedeltaIndex = create_pandas_abc_type("ABCTimedeltaIndex", "_typ", ("timedeltaindex",))
84-
ABCPeriodIndex = create_pandas_abc_type("ABCPeriodIndex", "_typ", ("periodindex",))
85-
ABCCategoricalIndex = create_pandas_abc_type("ABCCategoricalIndex", "_typ", ("categoricalindex",))
86-
ABCIndexClass = create_pandas_abc_type("ABCIndexClass", "_typ", ("index",
87-
"int64index",
88-
"rangeindex",
89-
"float64index",
90-
"multiindex",
91-
"datetimeindex",
92-
"timedeltaindex",
93-
"periodindex",
94-
"categoricalindex"))
79+
ABCInt64Index = create_pandas_abc_type("ABCInt64Index",
80+
"_typ", ("int64index",))
81+
ABCFloat64Index = create_pandas_abc_type("ABCFloat64Index",
82+
"_typ", ("float64index",))
83+
ABCMultiIndex = create_pandas_abc_type("ABCMultiIndex",
84+
"_typ", ("multiindex",))
85+
ABCDatetimeIndex = create_pandas_abc_type("ABCDatetimeIndex",
86+
"_typ", ("datetimeindex",))
87+
ABCTimedeltaIndex = create_pandas_abc_type("ABCTimedeltaIndex",
88+
"_typ", ("timedeltaindex",))
89+
ABCPeriodIndex = create_pandas_abc_type("ABCPeriodIndex",
90+
"_typ", ("periodindex",))
91+
ABCCategoricalIndex = create_pandas_abc_type("ABCCategoricalIndex",
92+
"_typ", ("categoricalindex",))
93+
ABCIndexClass = create_pandas_abc_type("ABCIndexClass",
94+
"_typ", ("index",
95+
"int64index",
96+
"rangeindex",
97+
"float64index",
98+
"multiindex",
99+
"datetimeindex",
100+
"timedeltaindex",
101+
"periodindex",
102+
"categoricalindex"))
95103

96104
ABCSeries = create_pandas_abc_type("ABCSeries", "_typ", ("series",))
97-
ABCDataFrame = create_pandas_abc_type("ABCDataFrame", "_typ", ("dataframe",))
105+
ABCDataFrame = create_pandas_abc_type("ABCDataFrame",
106+
"_typ", ("dataframe",))
98107
ABCPanel = create_pandas_abc_type("ABCPanel", "_typ", ("panel",))
99108
ABCSparseSeries = create_pandas_abc_type("ABCSparseSeries", "_subtyp",
100109
('sparse_series',
@@ -1758,8 +1767,7 @@ def is_bool_indexer(key):
17581767

17591768
def _default_index(n):
17601769
from pandas.core.index import RangeIndex
1761-
result = RangeIndex(0, int(n), name=None)
1762-
return result
1770+
return RangeIndex(0, n, name=None)
17631771

17641772

17651773
def ensure_float(arr):
@@ -2156,11 +2164,6 @@ def is_int64_dtype(arr_or_dtype):
21562164
tipo = _get_dtype_type(arr_or_dtype)
21572165
return issubclass(tipo, np.int64)
21582166

2159-
def is_int64_dtype(arr_or_dtype):
2160-
tipo = _get_dtype_type(arr_or_dtype)
2161-
return issubclass(tipo, np.int64)
2162-
2163-
21642167
def is_int_or_datetime_dtype(arr_or_dtype):
21652168
tipo = _get_dtype_type(arr_or_dtype)
21662169
return (issubclass(tipo, np.integer) or

pandas/core/dtypes.py

+3-2
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)