Skip to content

DOC: Added examples to pd.Index.get_loc #17380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0f16e2e
Added examples to pd.Index.get_loc
Aug 30, 2017
2c098cd
use target_klass so class name is properly updated for subclasses
Sep 1, 2017
9e425d6
TST: Enable tests in test_tools.py (#17405)
jschendel Sep 1, 2017
f7fe429
TST: remove tests and docs for legacy (pre 0.12) hdf5 support (#17404)
topper-123 Sep 1, 2017
8351f86
Tslib unused (#17402)
jbrockmendel Sep 1, 2017
1981b67
DOC: Cleaned references to pandas <v0.12 in docs (#17375)
topper-123 Sep 2, 2017
c2d0481
Remove unused _day and _month attrs (#17431)
jbrockmendel Sep 4, 2017
5bca6ce
DOC: Clean-up references to v12 to v14 (both included) (#17420)
topper-123 Sep 5, 2017
25d5299
BUG: Plotting Timedelta on y-axis #16953 (#17430)
s-weigand Sep 6, 2017
84a39f9
COMPAT: handle pyarrow deprecation of timestamps_to_ms in .from_panda…
jreback Sep 6, 2017
d457791
DOC/TST: Add examples to MultiIndex.get_level_values + related change…
topper-123 Sep 6, 2017
b869446
Dont re-pin total_seconds as it is already implemented (#17432)
jbrockmendel Sep 7, 2017
3a12687
BUG: Return local Timestamp.weekday_name attribute (#17354) (#17377)
mroeschke Sep 7, 2017
fd137f5
BUG: intersection of decreasing RangeIndexes (#17374)
toobaz Sep 7, 2017
93e23a7
Remove property that re-computed microsecond (#17331)
jbrockmendel Sep 7, 2017
20fee85
cleaned references to pandas v0.15 and v0.16 in docs (#17442)
topper-123 Sep 7, 2017
24b440e
BUG: revert collision warning (#17298)
deniederhut Sep 7, 2017
8a8a4fd
cdef out dtype for _Timestamp._get_field (#17457)
mroeschke Sep 7, 2017
9dc01c4
DOC: Add Timestamp, Period, Timedelta, and Interval to api.rst (#17424)
GuessWhoSamFoo Sep 7, 2017
aee2ae0
DOC: to_json (#17461)
majiang Sep 7, 2017
3a291bb
BUG: Index._searchsorted_monotonic(..., side='right') returns the lef…
jschendel Sep 7, 2017
ee6185e
COMPAT: Pypy tweaks (#17351)
mattip Sep 7, 2017
46832ac
Replace * imports with explicit imports; remove unused declared const…
jbrockmendel Sep 8, 2017
9c4e4c8
Removed Timedelta.is_populated and fixed spelling errors (#17469)
GuessWhoSamFoo Sep 8, 2017
7e4e8ac
PERF: Implement get_freq_code in cython frequencies (#17422)
jbrockmendel Sep 8, 2017
3ccb88c
Fix typo in setup.py introduced by 17422 (#17473)
jbrockmendel Sep 8, 2017
d6df8ea
Follow up to #17422 (#17472)
jbrockmendel Sep 8, 2017
fdbc6b8
MAINT: calcurate --> calculate in _doctools.py
gfyoung Sep 9, 2017
23050dc
BUG: Fix TypeError caused by GH13374 (#17465)
matthax Sep 10, 2017
c3ad501
Remove incorrect kwds from DateOffset tests (#17486)
jbrockmendel Sep 10, 2017
e6aed2e
Remove pyx dependencies from setup (#17478)
jbrockmendel Sep 10, 2017
42ed4f1
ENH: Add Styler.where (#17474)
Licht-T Sep 11, 2017
f3b6d1f
Add file-like object to docs (#17492)
rvernica Sep 11, 2017
46856c3
Implement _is_utc in timezones (#17419)
jbrockmendel Sep 11, 2017
34cc2e8
Follow-up to #17419 (#17497)
jbrockmendel Sep 12, 2017
9a84274
DOC: fix parquet example to not use ns
jreback Sep 12, 2017
d46b027
Prevent UnicodeDecodeError in pivot_table under Py2 (#17489)
mpenkov Sep 12, 2017
e682902
DEPR: Add warning for True for dropna of SeriesGroupBy.nth (#17493)
tnir Sep 12, 2017
83436af
COMPAT: Iteration should always yield a python scalar (#17491)
jreback Sep 12, 2017
633be31
DOC: grammatical mistake (#17511)
Giftlin Sep 13, 2017
f6d4d70
removed versionadded <0.17 (#17504)
topper-123 Sep 13, 2017
f11bbf2
DOC: grammatical mistakes (#17512)
Giftlin Sep 13, 2017
eef810e
COMPAT: followup to #17491 (#17503)
jreback Sep 13, 2017
fa557f7
De-privatize timezone funcs (#17502)
jbrockmendel Sep 13, 2017
2cf2566
Make *_range functions consistent (#17482)
jschendel Sep 14, 2017
97abd2c
TST: Made s3 related tests mock boto (#17388)
kirkhansen Sep 14, 2017
0097cb7
PERF: Avoid values in Categorical.set_categories (#17515)
TomAugspurger Sep 14, 2017
06a6e63
remove period_helper from non-period reqs (#17531)
jbrockmendel Sep 14, 2017
ad70ed4
Fix bug where offset.copy() != offset (#17452)
jbrockmendel Sep 14, 2017
94266d4
PERF: Faster CategoricalIndex from categorical (#17513)
TomAugspurger Sep 14, 2017
9b21c54
Remove unnecessary iNaT checks from _Period properties (#17421)
jbrockmendel Sep 15, 2017
72c3888
CLN: Fix Spelling Errors (#17535)
jschendel Sep 15, 2017
328c7e1
Cut/paste (most) remaining tz funcs to tslibs/timezones (#17526)
jbrockmendel Sep 15, 2017
9ec157b
DOC: Spelling + grammar in chainmap_impl.py (#17548)
Giftlin Sep 16, 2017
f5cfdbb
BUG: Set index when reading Stata file (#17328)
bashtage Sep 16, 2017
0674c42
Added examples to pd.Index.get_loc
Aug 30, 2017
71dfe09
use klass + add examples for CategoricalIndex, IntervalIndex and
Sep 1, 2017
12ce8d5
merge conflict
Sep 16, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ install:
# create our env
- cmd: conda create -n pandas python=%PYTHON_VERSION% cython pytest>=3.1.0 pytest-xdist
- cmd: activate pandas
- cmd: pip install moto
- SET REQ=ci\requirements-%PYTHON_VERSION%_WIN.run
- cmd: echo "installing requirements from %REQ%"
- cmd: conda install -n pandas --file=%REQ%
- cmd: conda list -n pandas
- cmd: echo "installing requirements from %REQ% - done"

# add some pip only reqs to the env
- SET REQ=ci\requirements-%PYTHON_VERSION%_WIN.pip
- cmd: echo "installing requirements from %REQ%"
- cmd: pip install -Ur %REQ%

# build em using the local source checkout in the correct windows env
- cmd: '%CMD_IN_ENV% python setup.py build_ext --inplace'

Expand Down
3 changes: 3 additions & 0 deletions asv_bench/benchmarks/categoricals.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def time_value_counts_dropna(self):
def time_rendering(self):
str(self.sel)

def time_set_categories(self):
self.ts.cat.set_categories(self.ts.cat.categories[::2])


class Categoricals3(object):
goal_time = 0.2
Expand Down
88 changes: 88 additions & 0 deletions asv_bench/benchmarks/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@
from pandas import Series, Period, PeriodIndex, date_range


class PeriodProperties(object):
def setup(self):
self.per = Period('2012-06-01', freq='M')

def time_year(self):
self.per.year

def time_month(self):
self.per.month

def time_quarter(self):
self.per.quarter

def time_day(self):
self.per.day

def time_hour(self):
self.per.hour

def time_minute(self):
self.per.second

def time_second(self):
self.per.second

def time_leap_year(self):
self.per.is_leapyear


class Constructor(object):
goal_time = 0.2

Expand Down Expand Up @@ -49,6 +78,65 @@ def time_value_counts_pindex(self):
self.i.value_counts()


class Properties(object):
def setup(self):
self.per = Period('2017-09-06 08:28', freq='min')

def time_year(self):
self.per.year

def time_month(self):
self.per.month

def time_day(self):
self.per.day

def time_hour(self):
self.per.hour

def time_minute(self):
self.per.minute

def time_second(self):
self.per.second

def time_is_leap_year(self):
self.per.is_leap_year

def time_quarter(self):
self.per.quarter

def time_qyear(self):
self.per.qyear

def time_week(self):
self.per.week

def time_daysinmonth(self):
self.per.daysinmonth

def time_dayofweek(self):
self.per.dayofweek

def time_dayofyear(self):
self.per.dayofyear

def time_start_time(self):
self.per.start_time

def time_end_time(self):
self.per.end_time

def time_to_timestamp():
self.per.to_timestamp()

def time_now():
self.per.now()

def time_asfreq():
self.per.asfreq('A')


class period_standard_indexing(object):
goal_time = 0.2

Expand Down
60 changes: 60 additions & 0 deletions asv_bench/benchmarks/timestamp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from .pandas_vb_common import *
from pandas import to_timedelta, Timestamp


class TimestampProperties(object):
goal_time = 0.2

def setup(self):
self.ts = Timestamp('2017-08-25 08:16:14')

def time_tz(self):
self.ts.tz

def time_offset(self):
self.ts.offset

def time_dayofweek(self):
self.ts.dayofweek

def time_weekday_name(self):
self.ts.weekday_name

def time_dayofyear(self):
self.ts.dayofyear

def time_week(self):
self.ts.week

def time_quarter(self):
self.ts.quarter

def time_days_in_month(self):
self.ts.days_in_month

def time_freqstr(self):
self.ts.freqstr

def time_is_month_start(self):
self.ts.is_month_start

def time_is_month_end(self):
self.ts.is_month_end

def time_is_quarter_start(self):
self.ts.is_quarter_start

def time_is_quarter_end(self):
self.ts.is_quarter_end

def time_is_year_start(self):
self.ts.is_quarter_end

def time_is_year_end(self):
self.ts.is_quarter_end

def time_is_leap_year(self):
self.ts.is_quarter_end

def time_microsecond(self):
self.ts.microsecond
1 change: 1 addition & 0 deletions ci/install_circle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ time conda create -n pandas -q --file=${REQ_BUILD} || exit 1
time conda install -n pandas pytest>=3.1.0 || exit 1

source activate pandas
time pip install moto || exit 1

# build but don't install
echo "[build em]"
Expand Down
2 changes: 1 addition & 1 deletion ci/install_travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if [ -e ${REQ} ]; then
fi

time conda install -n pandas pytest>=3.1.0
time pip install pytest-xdist
time pip install pytest-xdist moto

if [ "$LINT" ]; then
conda install flake8
Expand Down
Empty file added ci/requirements-2.7_WIN.pip
Empty file.
2 changes: 1 addition & 1 deletion ci/requirements-3.5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ echo "install 35"
conda remove -n pandas python-dateutil --force
pip install python-dateutil

conda install -n pandas -c conda-forge feather-format pyarrow=0.4.1
conda install -n pandas -c conda-forge feather-format pyarrow=0.5.0
Empty file.
Empty file added ci/requirements-3.6_WIN.pip
Empty file.
1 change: 1 addition & 0 deletions ci/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ cython
pytest>=3.1.0
pytest-cov
flake8
moto
2 changes: 1 addition & 1 deletion doc/source/10min.rst
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ the quarter end:
Categoricals
------------

Since version 0.15, pandas can include categorical data in a ``DataFrame``. For full docs, see the
pandas can include categorical data in a ``DataFrame``. For full docs, see the
:ref:`categorical introduction <categorical>` and the :ref:`API documentation <api.categorical>`.

.. ipython:: python
Expand Down
46 changes: 11 additions & 35 deletions doc/source/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ See the :ref:`Indexing and Selecting Data <indexing>` for general indexing docum
should be avoided. See :ref:`Returning a View versus Copy
<indexing.view_versus_copy>`

.. warning::

In 0.15.0 ``Index`` has internally been refactored to no longer sub-class ``ndarray``
but instead subclass ``PandasObject``, similarly to the rest of the pandas objects. This should be
a transparent change with only very limited API implications (See the :ref:`Internal Refactoring <whatsnew_0150.refactoring>`)

See the :ref:`cookbook<cookbook.selection>` for some advanced strategies

.. _advanced.hierarchical:
Expand Down Expand Up @@ -270,9 +264,6 @@ Passing a list of labels or tuples works similar to reindexing:
Using slicers
~~~~~~~~~~~~~

.. versionadded:: 0.14.0

In 0.14.0 we added a new way to slice multi-indexed objects.
You can slice a multi-index by providing multiple indexers.

You can provide any of the selectors as if you are indexing by label, see :ref:`Selection by Label <indexing.label>`,
Expand Down Expand Up @@ -384,7 +375,7 @@ selecting data at a particular level of a MultiIndex easier.

.. ipython:: python

# using the slicers (new in 0.14.0)
# using the slicers
df.loc[(slice(None),'one'),:]

You can also select on the columns with :meth:`~pandas.MultiIndex.xs`, by
Expand All @@ -397,7 +388,7 @@ providing the axis argument

.. ipython:: python

# using the slicers (new in 0.14.0)
# using the slicers
df.loc[:,(slice(None),'one')]

:meth:`~pandas.MultiIndex.xs` also allows selection with multiple keys
Expand All @@ -408,11 +399,9 @@ providing the axis argument

.. ipython:: python

# using the slicers (new in 0.14.0)
# using the slicers
df.loc[:,('bar','one')]

.. versionadded:: 0.13.0

You can pass ``drop_level=False`` to :meth:`~pandas.MultiIndex.xs` to retain
the level that was selected

Expand Down Expand Up @@ -636,19 +625,16 @@ Index Types
We have discussed ``MultiIndex`` in the previous sections pretty extensively. ``DatetimeIndex`` and ``PeriodIndex``
are shown :ref:`here <timeseries.overview>`. ``TimedeltaIndex`` are :ref:`here <timedeltas.timedeltas>`.

In the following sub-sections we will highlite some other index types.
In the following sub-sections we will highlight some other index types.

.. _indexing.categoricalindex:

CategoricalIndex
~~~~~~~~~~~~~~~~

.. versionadded:: 0.16.1

We introduce a ``CategoricalIndex``, a new type of index object that is useful for supporting
indexing with duplicates. This is a container around a ``Categorical`` (introduced in v0.15.0)
and allows efficient indexing and storage of an index with a large number of duplicated elements. Prior to 0.16.1,
setting the index of a ``DataFrame/Series`` with a ``category`` dtype would convert this to regular object-based ``Index``.
``CategoricalIndex`` is a type of index that is useful for supporting
indexing with duplicates. This is a container around a ``Categorical``
and allows efficient indexing and storage of an index with a large number of duplicated elements.

.. ipython:: python

Expand All @@ -659,7 +645,7 @@ setting the index of a ``DataFrame/Series`` with a ``category`` dtype would conv
df.dtypes
df.B.cat.categories

Setting the index, will create create a ``CategoricalIndex``
Setting the index, will create a ``CategoricalIndex``

.. ipython:: python

Expand Down Expand Up @@ -695,7 +681,7 @@ Groupby operations on the index will preserve the index nature as well
Reindexing operations, will return a resulting index based on the type of the passed
indexer, meaning that passing a list will return a plain-old-``Index``; indexing with
a ``Categorical`` will return a ``CategoricalIndex``, indexed according to the categories
of the PASSED ``Categorical`` dtype. This allows one to arbitrarly index these even with
of the PASSED ``Categorical`` dtype. This allows one to arbitrarily index these even with
values NOT in the categories, similarly to how you can reindex ANY pandas index.

.. ipython :: python
Expand Down Expand Up @@ -736,23 +722,13 @@ Int64Index and RangeIndex
Prior to 0.18.0, the ``Int64Index`` would provide the default index for all ``NDFrame`` objects.

``RangeIndex`` is a sub-class of ``Int64Index`` added in version 0.18.0, now providing the default index for all ``NDFrame`` objects.
``RangeIndex`` is an optimized version of ``Int64Index`` that can represent a monotonic ordered set. These are analagous to python `range types <https://docs.python.org/3/library/stdtypes.html#typesseq-range>`__.
``RangeIndex`` is an optimized version of ``Int64Index`` that can represent a monotonic ordered set. These are analogous to python `range types <https://docs.python.org/3/library/stdtypes.html#typesseq-range>`__.

.. _indexing.float64index:

Float64Index
~~~~~~~~~~~~

.. note::

As of 0.14.0, ``Float64Index`` is backed by a native ``float64`` dtype
array. Prior to 0.14.0, ``Float64Index`` was backed by an ``object`` dtype
array. Using a ``float64`` dtype in the backend speeds up arithmetic
operations by about 30x and boolean indexing operations on the
``Float64Index`` itself are about 2x as fast.

.. versionadded:: 0.13.0

By default a ``Float64Index`` will be automatically created when passing floating, or mixed-integer-floating values in index creation.
This enables a pure label-based slicing paradigm that makes ``[],ix,loc`` for scalar indexing and slicing work exactly the
same.
Expand Down Expand Up @@ -987,7 +963,7 @@ index can be somewhat complicated. For example, the following does not work:
s.loc['c':'e'+1]

A very common use case is to limit a time series to start and end at two
specific dates. To enable this, we made the design design to make label-based
specific dates. To enable this, we made the design to make label-based
slicing include both endpoints:

.. ipython:: python
Expand Down
Loading