Skip to content

DOC: Added docs to clarify that MultiIndex.set_levels() interprets passed values as new components of the .levels attribute (#28294) #28797

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
wants to merge 122 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
e8256cc
DOC: added docs for MultiIndex.set_levels (#28294)
hweecat Oct 5, 2019
d9130f2
edit set_levels docstring with additional examples
hweecat Oct 8, 2019
46d88c1
CLN: Exception*2 in groupby wrapper (#28771)
jbrockmendel Oct 8, 2019
1ef3637
TST: un-xfail 1 passing maybe_promote test (#28850)
jbrockmendel Oct 8, 2019
f625730
remove doc note about apply applying a function to the first element …
tlynch1315 Oct 8, 2019
c9b6261
TST: un-xfail 22 tests (#28856)
jbrockmendel Oct 8, 2019
25b1859
TST: Improve compatibility with pypy error messages (#28844)
rlamy Oct 8, 2019
29e56df
TST: Fix not-boxed maybe_promote test (#28852)
jbrockmendel Oct 8, 2019
acde02b
TST: fix 24 xfails in maybe_promote (#28833)
jbrockmendel Oct 8, 2019
5122241
CLN: Assorted cleanups (#28848)
jbrockmendel Oct 8, 2019
df2e081
Clean up Abstract and Naming Definitions for GroupBy (#28847)
WillAyd Oct 8, 2019
43687c0
DOC: Fix missing periods and non capitalized summary beginnings (#28858)
refactoriel Oct 9, 2019
93183ba
fix unnecessary sort in pd.read_json and orient="index" (#28606)
KimDoubleB Oct 9, 2019
71f8ab9
CLN: dont catch Exception in groupby var (#28883)
jbrockmendel Oct 10, 2019
548f83d
CLN: dont catch on groupby.mean (#28878)
jbrockmendel Oct 10, 2019
5cbd82b
CLN: assorted cleanups, remove unicode checks in cython (#28879)
jbrockmendel Oct 10, 2019
fcea0dc
No catching needed for median (#28873)
jbrockmendel Oct 10, 2019
959a760
read_hdf closes HDF5 stores that it didn't open. (#28700)
kboone Oct 10, 2019
4f97ca4
DOC: Fix commpiler typo in contributing.rst (#28891)
shaido987 Oct 10, 2019
9743154
TST: Fix maybe_promote floating non-boxed tests (#28880)
jbrockmendel Oct 10, 2019
9a3e1ef
TST: Fix xfails for non-box maybe_promote on integer dtypes (#28864)
jbrockmendel Oct 10, 2019
eca6079
pandas.io.formats.style.Styler.set_table_attributes: Parameter attrib…
roshni-b Oct 10, 2019
0c4404b
DOC: Fixed PR06 errors in pandas.api.extensions.ExtensionArray (#28885)
roshni-b Oct 10, 2019
de2e086
REF: simplify maybe_promote (#28899)
jbrockmendel Oct 10, 2019
d8f9be7
Fix typo (#28915)
KimDoubleB Oct 11, 2019
230a61a
TYPING: lockdown test modules failing mypy (#28914)
simonjayhawkins Oct 11, 2019
fab2c90
CLN: simplify maybe_promote in float and complex cases (#28913)
jbrockmendel Oct 11, 2019
e1e51df
TYPING: errors reported by mypy 0.730 (#28910)
simonjayhawkins Oct 11, 2019
a4c92ca
clean tests/indexing/common.py (#28904)
topper-123 Oct 11, 2019
3954fa7
REF: use fused types for groupby_helper (#28886)
jbrockmendel Oct 11, 2019
6241b9d
BUG: Allow all int types for merge (GH28870) (#28875)
jjlkant Oct 11, 2019
0474c7f
TST: Fix 36 maybe_promote xfails wanting np.bytes_ instead of np.obje…
jbrockmendel Oct 11, 2019
3fba92e
TYPING: fix type annotation for pandas.io.formats.format._binify (#28…
simonjayhawkins Oct 11, 2019
894eac6
TST: add test coverage for maybe_promote (#23982)
h-vetinari Oct 11, 2019
981299c
TST: Use fixtures instead of setup_method for index tests (#28865)
jschendel Oct 11, 2019
7ea5c96
CLN: Exception (#28853)
jbrockmendel Oct 11, 2019
a31e160
CLN: assorted cleanups, mostly post-black fixups (#28857)
jbrockmendel Oct 11, 2019
0748c91
DOC: PR06 docstring fixes (#28807)
tolaa001 Oct 11, 2019
54b1151
TST: Allow for multiple variables on the same line in docstring valid…
ChiefMilesEdgeworth Oct 11, 2019
d6b058d
CLN: try/except cleanups (#28939)
jbrockmendel Oct 12, 2019
c387a28
BUG: Avoid undefined behaviour when converting from float to timedelt…
siddhesh Oct 12, 2019
fad037e
Added note to 'contributing.rst file', telling users to append GH Iss…
S3rbane Oct 12, 2019
4ade26b
REF: maybe_promote refactor/cleanup (#28897)
jbrockmendel Oct 12, 2019
1e92886
API: Add various deprecated attributes to ._deprecated (#28805)
topper-123 Oct 12, 2019
56b2fd8
TST: Test pivot_table() with categorical data (#28803)
ryankarlos Oct 12, 2019
25059ee
BUG: Need 'windows-1252' encoding for locale names. (#27368)
timcera Oct 12, 2019
f7d162b
DOC: disable nbsphinx including requirejs (#28940)
jorisvandenbossche Oct 12, 2019
625c550
CLN: fix mypy errors in pandas/tests/extension/test_numpy.py #28926 (…
lukasbk Oct 13, 2019
0eee324
TST: add test_series_any_timedelta for GH17667 (#28942)
rohitsanj Oct 13, 2019
2931f02
PR06 doc string fixes (#28946)
tolaa001 Oct 13, 2019
04d7931
fix #28926 pandas\api\test_api.py mypy errors (#28935)
yogendrasoni Oct 13, 2019
06a6b49
Eliminated _WriterBase class, removed unused fixtures from methods in…
dayoreke Oct 13, 2019
851ca1a
Fix mypy errors for pandas\tests\* #28926 (test_algos.py) (#28960)
lrm25 Oct 14, 2019
18a9e4c
DOC: Fixed PR08 and PR09 docstring errors in pandas.Series (#28845)
jb8429 Oct 14, 2019
2f80feb
BUG: Partial fix for docstring validation for parameters (#28765)
ChiefMilesEdgeworth Oct 14, 2019
5b0bf23
DOC: fix formatting in the ExtensionArray docstrings (#28686)
HughKelley Oct 14, 2019
8c5941c
BUG: use EA.astype in ExtensionBlock.to_native_types (#28841)
jorisvandenbossche Oct 14, 2019
97c6567
Document 3.8 compatibility (#28982)
TomAugspurger Oct 15, 2019
80412cc
CI: 3.8 build (#28730)
jbrockmendel Oct 15, 2019
c65cfb6
remove unnecessary get_value_at calls (#28977)
jbrockmendel Oct 15, 2019
3eca505
add types tot rank_1d_, rank_2d (#28978)
jbrockmendel Oct 15, 2019
3b34368
CLN: Exception in _libs (#28967)
jbrockmendel Oct 15, 2019
125739f
CLN: pandas-dev#28926 Fix pandas/tests/tseries/offsets/test_offsets_p…
aaditya-panik Oct 15, 2019
6dc53bb
CLN: pandas-dev#28926 Fix mypy errors in pandas/tests/io/parser/conft…
aaditya-panik Oct 15, 2019
19c8fad
DOC: 0.25.2 whatsnew cleanup (#29000)
TomAugspurger Oct 15, 2019
8d3fec9
DOC: fix is_scalar documentation (#28998) (#29004)
andreasbuhr Oct 15, 2019
74bbbb0
Setuptools CI fixup (#29010)
TomAugspurger Oct 15, 2019
de67bb7
CLN: Fix mypy errors in pandas/tests/io/test_sql.py Reverted and adde…
aaditya-panik Oct 16, 2019
d52850f
DOC: Reference level name as Term of HDFStore.select query (#28791) (…
nrebena Oct 16, 2019
0a108f0
CLN: move small bits outside of try/excepts (#28962)
jbrockmendel Oct 16, 2019
c903e5e
CLN: Consistent and Annotated Return Type of _iterate_slices (#28958)
WillAyd Oct 16, 2019
b632ca0
restore xfail (#29013)
jbrockmendel Oct 16, 2019
79a5f7c
To html encoding add (#28692)
Oct 16, 2019
a0d01b8
add uint64 support for some libgroupby funcs (#28931)
jbrockmendel Oct 16, 2019
86e187f
BUG: CategoricalIndex allowed reindexing duplicate sources (#28257)
batterseapower Oct 16, 2019
46e89b0
Separate MultiIndex names from levels (#27242)
topper-123 Oct 16, 2019
5ad908e
DOC: fix code-block in the reshaping docs (#28838)
oktaysabak Oct 16, 2019
fdc322a
CLN: Fix mypy error in pandas/tests/computation/test_eval.py (#29007)
immaxchen Oct 16, 2019
b63f829
CLN: Clean DirNameMixin (#28957)
topper-123 Oct 16, 2019
bff90a3
REF: de-duplicate groupby_helper code (#28934)
jbrockmendel Oct 16, 2019
30a0e2e
CLN: fix mypy error pandas/tests/plotting/test_backend.py (#29016)
saska Oct 16, 2019
143eb38
REF: re-raise AssertionError unchanged (#28959)
jbrockmendel Oct 16, 2019
9486f04
tests/indexing/test_coercion.py typefix (#28990)
lukasbk Oct 16, 2019
da3d0d9
DEPR: remove previously-deprecated broadcast/reduce kwargs from DataF…
jbrockmendel Oct 16, 2019
9d45934
BUG: Fix TypeError in _cython_agg_blocks (#29035)
jbrockmendel Oct 17, 2019
509eb14
CI: xfail on numpy 1.18 (#29057)
jbrockmendel Oct 17, 2019
6d35836
Stop catching TypeError in groupby methods (#29060)
jbrockmendel Oct 17, 2019
b0f33b3
API: Restore getting name from MultiIndex level (#29061)
TomAugspurger Oct 18, 2019
709436d
fixed issue of mypy for test_ujson (#29022)
iamrajhans Oct 18, 2019
f556a71
CLN: derivation of nogil param (#29047)
jbrockmendel Oct 18, 2019
827440a
REF: remove groupby_helper (#29040)
jbrockmendel Oct 18, 2019
1e4fe0a
ENH: Informative dtype message for for assert_series_equal (#28993)
moi90 Oct 18, 2019
2683954
TST: add regression test for all-none-groupby (#29067)
crepererum Oct 18, 2019
45dc6d3
Fix mypy errors for pandas\tests\*: test_convert_to.py (#28965)
lrm25 Oct 18, 2019
58d34d9
CLN: catch less in groupby (#29077)
jbrockmendel Oct 18, 2019
e54b995
CLN: simplify take_2d_multi (#29065)
jbrockmendel Oct 18, 2019
2701f52
REF: use fused types in algos_rank_helper (#29044)
jbrockmendel Oct 18, 2019
09a9f5f
DOC: updated categorical docstring (#29068)
javad94 Oct 18, 2019
b372ac4
CLN: tighten exception catching in indexes (#29078)
jbrockmendel Oct 19, 2019
09fc1b4
explain set_levels().levels examples + formatting
hweecat Oct 19, 2019
5bdd7db
explain set_levels().levels examples + formatting
hweecat Oct 19, 2019
9c4a371
[#22550] Remove TestData from series-tests test_quantile.py (#29096)
SaturnFromTitan Oct 19, 2019
d186f77
Merge branches 'docfix-multiindex-setlevels' and 'docfix-multiindex-s…
hweecat Oct 19, 2019
a2f5ae2
comments, catch less (#29088)
jbrockmendel Oct 19, 2019
cb99e24
REF: remove algos_rank_helper (#29086)
jbrockmendel Oct 19, 2019
930dd84
CLN: Exception in DataFrame._reduce (#29085)
jbrockmendel Oct 19, 2019
7c8c8c8
[#22550] Remove TestData from series-tests test_operators.py (#29084)
SaturnFromTitan Oct 19, 2019
e4afa45
TST: 2d index when constructing dataframe (#25416). (#29083)
jhereth Oct 19, 2019
cb76dcb
TST: regression test for groupby with datetime and timedelta (#15562)…
jhereth Oct 19, 2019
6931051
CLN: cython and docstring cleanups (#29089)
jbrockmendel Oct 19, 2019
04893a9
BUG: parse_time_string failing to raise TypeError (#29098)
jbrockmendel Oct 19, 2019
971d191
explain set_levels().levels examples + formatting
hweecat Oct 19, 2019
8ccc7c7
formatting changes
hweecat Oct 20, 2019
36803b9
formatting changes
hweecat Oct 20, 2019
e623f0f
Add a regression test for the timezone issue (#29097)
grigoriosgiann Oct 20, 2019
d2d8785
Fix typing errors (#29115)
AbhijeetKrishnan Oct 20, 2019
9f03837
Fix typing errors (#29114)
AbhijeetKrishnan Oct 20, 2019
9026a79
DOC: added docs for MultiIndex.set_levels (#28294)
hweecat Oct 5, 2019
4f5e38d
edit set_levels docstring with additional examples
hweecat Oct 8, 2019
c00cc9d
explain set_levels().levels examples + formatting
hweecat Oct 19, 2019
211574b
explain set_levels().levels examples + formatting
hweecat Oct 19, 2019
93c84bb
Merge branch 'docfix-multiindex-setlevels' of https://github.com/hwee…
hweecat Oct 21, 2019
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
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ matrix:
- python: 3.5

include:
- dist: bionic
# 18.04
python: 3.8-dev
env:
- JOB="3.8-dev" PATTERN="(not slow and not network)"

- dist: trusty
env:
- JOB="3.7" ENV_FILE="ci/deps/travis-37.yaml" PATTERN="(not slow and not network)"
Expand Down Expand Up @@ -71,24 +77,27 @@ before_install:
# This overrides travis and tells it to look nowhere.
- export BOTO_CONFIG=/dev/null


install:
- echo "install start"
- ci/prep_cython_cache.sh
- ci/setup_env.sh
- ci/submit_cython_cache.sh
- echo "install done"


before_script:
# display server (for clipboard functionality) needs to be started here,
# does not work if done in install:setup_env.sh (GH-26103)
- export DISPLAY=":99.0"
- echo "sh -e /etc/init.d/xvfb start"
- sh -e /etc/init.d/xvfb start
- if [ "$JOB" != "3.8-dev" ]; then sh -e /etc/init.d/xvfb start; fi
- sleep 3

script:
- echo "script start"
- source activate pandas-dev
- echo "$JOB"
- if [ "$JOB" != "3.8-dev" ]; then source activate pandas-dev; fi
- ci/run_tests.sh

after_script:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SeriesConstructors:
def setup(self, data_fmt, with_index, dtype):
if data_fmt in (gen_of_str, gen_of_tuples) and with_index:
raise NotImplementedError(
"Series constructors do not support " "using generators with indexes"
"Series constructors do not support using generators with indexes"
)
N = 10 ** 4
if dtype == "float":
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def time_add(self, engine, threads):

def time_and(self, engine, threads):
pd.eval(
"(self.df > 0) & (self.df2 > 0) & " "(self.df3 > 0) & (self.df4 > 0)",
"(self.df > 0) & (self.df2 > 0) & (self.df3 > 0) & (self.df4 > 0)",
engine=engine,
)

Expand Down
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/io/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def time_write_store_table_dc(self):

def time_query_store_table_wide(self):
self.store.select(
"table_wide", where="index > self.start_wide and " "index < self.stop_wide"
"table_wide", where="index > self.start_wide and index < self.stop_wide"
)

def time_query_store_table(self):
self.store.select("table", where="index > self.start and " "index < self.stop")
self.store.select("table", where="index > self.start and index < self.stop")

def time_store_repr(self):
repr(self.store)
Expand Down
19 changes: 19 additions & 0 deletions ci/build38.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash -e
# Special build for python3.8 until numpy puts its own wheels up

sudo apt-get install build-essential gcc xvfb
pip install --no-deps -U pip wheel setuptools
pip install python-dateutil pytz cython pytest pytest-xdist hypothesis

# Possible alternative for getting numpy:
pip install --pre -f https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com/ numpy

python setup.py build_ext -inplace
python -m pip install --no-build-isolation -e .

python -c "import sys; print(sys.version_info)"
python -c "import pandas as pd"
python -c "import hypothesis"

# TODO: Is there anything else in setup_env that we really want to do?
# ci/setup_env.sh
2 changes: 1 addition & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
MSG='Check for non-standard imports' ; echo $MSG
invgrep -R --include="*.py*" -E "from pandas.core.common import " pandas
invgrep -R --include="*.py*" -E "from collections.abc import " pandas
# invgrep -R --include="*.py*" -E "from numpy import nan " pandas # GH#24822 not yet implemented since the offending imports have not all been removed
invgrep -R --include="*.py*" -E "from numpy import nan " pandas
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check for use of exec' ; echo $MSG
Expand Down
5 changes: 5 additions & 0 deletions ci/setup_env.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash -e

if [ "$JOB" == "3.8-dev" ]; then
/bin/bash ci/build38.sh
exit 0
fi

# edit the locale file if needed
if [ -n "$LOCALE_OVERRIDE" ]; then
Expand Down Expand Up @@ -51,6 +55,7 @@ echo
echo "update conda"
conda config --set ssl_verify false
conda config --set quiet true --set always_yes true --set changeps1 false
conda install pip # create conda to create a historical artifact for pip & setuptools
conda update -n base conda

echo "conda info -a"
Expand Down
7 changes: 5 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
plot_pre_code = """import numpy as np
import pandas as pd"""

# nbsphinx do not use requirejs (breaks bootstrap)
nbsphinx_requirejs_path = ""

# Add any paths that contain templates here, relative to this directory.
templates_path = ["../_templates"]

Expand Down Expand Up @@ -628,11 +631,11 @@ def linkcode_resolve(domain, info):
fn = os.path.relpath(fn, start=os.path.dirname(pandas.__file__))

if "+" in pandas.__version__:
return "http://github.com/pandas-dev/pandas/blob/master/pandas/" "{}{}".format(
return "http://github.com/pandas-dev/pandas/blob/master/pandas/{}{}".format(
fn, linespec
)
else:
return "http://github.com/pandas-dev/pandas/blob/" "v{}/pandas/{}{}".format(
return "http://github.com/pandas-dev/pandas/blob/v{}/pandas/{}{}".format(
pandas.__version__, fn, linespec
)

Expand Down
5 changes: 4 additions & 1 deletion doc/source/development/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ installed (or you wish to install a newer version) you can install a compiler
yum groupinstall "Development Tools"

For other Linux distributions, consult your favourite search engine for
commpiler installation instructions.
compiler installation instructions.

Let us know if you have any difficulties by opening an issue or reaching out on
`Gitter`_.
Expand Down Expand Up @@ -949,6 +949,9 @@ the expected correct result::

assert_frame_equal(pivoted, expected)

Please remember to add the Github Issue Number as a comment to a new test.
E.g. "# brief comment, see GH#28907"

Transitioning to ``pytest``
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion doc/source/getting_started/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Instructions for installing from source,
Python version support
----------------------

Officially Python 3.5.3 and above, 3.6, and 3.7.
Officially Python 3.5.3 and above, 3.6, 3.7, and 3.8.

Installing pandas
-----------------
Expand Down
36 changes: 25 additions & 11 deletions doc/source/user_guide/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -783,27 +783,41 @@ values **not** in the categories, similarly to how you can reindex **any** panda

.. ipython:: python

df2.reindex(['a', 'e'])
df2.reindex(['a', 'e']).index
df2.reindex(pd.Categorical(['a', 'e'], categories=list('abcde')))
df2.reindex(pd.Categorical(['a', 'e'], categories=list('abcde'))).index
df3 = pd.DataFrame({'A': np.arange(3),
'B': pd.Series(list('abc')).astype('category')})
df3 = df3.set_index('B')
df3

.. ipython:: python

df3.reindex(['a', 'e'])
df3.reindex(['a', 'e']).index
df3.reindex(pd.Categorical(['a', 'e'], categories=list('abe')))
df3.reindex(pd.Categorical(['a', 'e'], categories=list('abe'))).index

.. warning::

Reshaping and Comparison operations on a ``CategoricalIndex`` must have the same categories
or a ``TypeError`` will be raised.

.. code-block:: ipython
.. ipython:: python

In [9]: df3 = pd.DataFrame({'A': np.arange(6), 'B': pd.Series(list('aabbca')).astype('category')})
df4 = pd.DataFrame({'A': np.arange(2),
'B': list('ba')})
df4['B'] = df4['B'].astype(CategoricalDtype(list('ab')))
df4 = df4.set_index('B')
df4.index

In [11]: df3 = df3.set_index('B')
df5 = pd.DataFrame({'A': np.arange(2),
'B': list('bc')})
df5['B'] = df5['B'].astype(CategoricalDtype(list('bc')))
df5 = df5.set_index('B')
df5.index

In [11]: df3.index
Out[11]: CategoricalIndex(['a', 'a', 'b', 'b', 'c', 'a'], categories=['a', 'b', 'c'], ordered=False, name='B', dtype='category')
.. code-block:: ipython

In [12]: pd.concat([df2, df3])
TypeError: categories must match existing categories when appending
In [1]: pd.concat([df4, df5])
TypeError: categories must match existing categories when appending

.. _indexing.rangeindex:

Expand Down
34 changes: 33 additions & 1 deletion doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3811,6 +3811,8 @@ storing/selecting from homogeneous index ``DataFrames``.
# the levels are automatically included as data columns
store.select('df_mi', 'foo=bar')

.. note::
The ``index`` keyword is reserved and cannot be use as a level name.

.. _io.hdf5-query:

Expand All @@ -3829,6 +3831,7 @@ A query is specified using the ``Term`` class under the hood, as a boolean expre

* ``index`` and ``columns`` are supported indexers of ``DataFrames``.
* if ``data_columns`` are specified, these can be used as additional indexers.
* level name in a MultiIndex, with default name ``level_0``, ``level_1``, … if not provided.

Valid comparison operators are:

Expand Down Expand Up @@ -3947,7 +3950,7 @@ space. These are in terms of the total number of rows in a table.

.. _io.hdf5-timedelta:

Using timedelta64[ns]
Query timedelta64[ns]
+++++++++++++++++++++

You can store and query using the ``timedelta64[ns]`` type. Terms can be
Expand All @@ -3966,6 +3969,35 @@ specified in the format: ``<float>(<unit>)``, where float may be signed (and fra
store.append('dftd', dftd, data_columns=True)
store.select('dftd', "C<'-3.5D'")

Query MultiIndex
++++++++++++++++

Selecting from a ``MultiIndex`` can be achieved by using the name of the level.

.. ipython:: python

df_mi.index.names
store.select('df_mi', "foo=baz and bar=two")

If the ``MultiIndex`` levels names are ``None``, the levels are automatically made available via
the ``level_n`` keyword with ``n`` the level of the ``MultiIndex`` you want to select from.

.. ipython:: python

index = pd.MultiIndex(
levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
)
df_mi_2 = pd.DataFrame(np.random.randn(10, 3),
index=index, columns=["A", "B", "C"])
df_mi_2

store.append("df_mi_2", df_mi_2)

# the levels are automatically included as data columns with keyword level_n
store.select("df_mi_2", "level_0=foo and level_1=two")


Indexing
++++++++

Expand Down
16 changes: 8 additions & 8 deletions doc/source/user_guide/reshaping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -728,14 +728,14 @@ Suppose we wanted to pivot ``df`` such that the ``col`` values are columns,
``row`` values are the index, and the mean of ``val0`` are the values? In
particular, the resulting DataFrame should look like:

.. note::

col col0 col1 col2 col3 col4
row
row0 0.77 0.605 NaN 0.860 0.65
row2 0.13 NaN 0.395 0.500 0.25
row3 NaN 0.310 NaN 0.545 NaN
row4 NaN 0.100 0.395 0.760 0.24
.. code-block:: text

col col0 col1 col2 col3 col4
row
row0 0.77 0.605 NaN 0.860 0.65
row2 0.13 NaN 0.395 0.500 0.25
row3 NaN 0.310 NaN 0.545 NaN
row4 NaN 0.100 0.395 0.760 0.24

This solution uses :func:`~pandas.pivot_table`. Also note that
``aggfunc='mean'`` is the default. It is included here to be explicit.
Expand Down
Loading