Skip to content

BUG: Issue with to_latex and MultiIndex column format. GH8336 #8784

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 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
eb1536b
Issue with to_latex and MultiIndex column format
kotfic Nov 11, 2014
e366f68
Must include MultiIndex Column names
kotfic Nov 11, 2014
8bae0d4
BUG: ensure we use group sizes, not group counts, in transform (GH9697)
dsm054 Mar 22, 2015
25baa7e
DOC: correct currenmoduel for API stringmethods
jorisvandenbossche Mar 22, 2015
29377be
DOC: add v0.16.1.txt to whatsnew
jreback Mar 22, 2015
61086a7
DOC: add automatic content to 0.16.1 whatsnew file
jorisvandenbossche Mar 22, 2015
3fb908b
DOC: add DataFrame.assign to API docs
shoyer Mar 23, 2015
9dc9f0c
DOC: try to use matplotlib style (mpl >= 1.4) in all docs
jorisvandenbossche Mar 23, 2015
3a3429f
Merge pull request #9702 from jorisvandenbossche/whatsnew0161
jorisvandenbossche Mar 23, 2015
713fe11
Merge pull request #9699 from dsm054/fix-transform-length-mismatch
jreback Mar 23, 2015
9083e98
Merge pull request #9706 from jorisvandenbossche/doc-plots
jorisvandenbossche Mar 24, 2015
dcc7431
Merge pull request #9705 from shoyer/assign-api-docs
jorisvandenbossche Mar 24, 2015
03f9af0
TST: Fix dateutil version check
evanpw Mar 25, 2015
31782f4
Merge pull request #9725 from evanpw/tslib_test
jreback Mar 25, 2015
f7c7ee0
Document how to drop duplicate indices
flying-sheep Mar 24, 2015
beb0812
DOC: edit indexing.rst a bit
jreback Mar 25, 2015
a477202
BUG: datetime/timedelta Series quantile() call
Mar 21, 2015
8d2818e
Merge pull request #9701 from williamhogman/feature-dashed-quarters
jreback Mar 26, 2015
64c3921
Issue with to_latex and MultiIndex column format
kotfic Nov 11, 2014
079b19c
Must include MultiIndex Column names
kotfic Nov 11, 2014
9718367
Merge branch 'master' of https://github.com/kotfic/pandas
kotfic Mar 26, 2015
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
8 changes: 5 additions & 3 deletions doc/source/10min.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from pandas import options
import pandas as pd
np.set_printoptions(precision=4, suppress=True)
options.display.mpl_style='default'
import matplotlib
try:
matplotlib.style.use('ggplot')
except AttributeError:
options.display.mpl_style = 'default'
options.display.max_rows=15

#### portions of this were borrowed from the
Expand Down Expand Up @@ -695,8 +699,6 @@ Plotting

import matplotlib.pyplot as plt
plt.close('all')
from pandas import options
options.display.mpl_style='default'

.. ipython:: python

Expand Down
3 changes: 1 addition & 2 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,6 @@ String handling
strings and apply several methods to it. These can be acccessed like
``Series.str.<function/property>``.

.. currentmodule:: pandas.core.strings

.. autosummary::
:toctree: generated/
:template: autosummary/accessor_method.rst
Expand Down Expand Up @@ -863,6 +861,7 @@ Combining / joining / merging
:toctree: generated/

DataFrame.append
DataFrame.assign
DataFrame.join
DataFrame.merge
DataFrame.update
Expand Down
1 change: 0 additions & 1 deletion doc/source/categorical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pandas import *
import pandas as pd
np.set_printoptions(precision=4, suppress=True)
options.display.mpl_style='default'
options.display.max_rows=15


Expand Down
6 changes: 5 additions & 1 deletion doc/source/computation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
import pandas.util.testing as tm
randn = np.random.randn
np.set_printoptions(precision=4, suppress=True)
import matplotlib
try:
matplotlib.style.use('ggplot')
except AttributeError:
options.display.mpl_style = 'default'
import matplotlib.pyplot as plt
plt.close('all')
options.display.mpl_style='default'
options.display.max_rows=15

Computational tools
Expand Down
7 changes: 6 additions & 1 deletion doc/source/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
np.random.seed(123456)

pd.options.display.max_rows=15
pd.options.display.mpl_style='default'

import matplotlib
try:
matplotlib.style.use('ggplot')
except AttributeError:
pd.options.display.mpl_style = 'default'

np.set_printoptions(precision=4, suppress=True)

Expand Down
6 changes: 5 additions & 1 deletion doc/source/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Frequently Asked Questions (FAQ)
from pandas.tseries.offsets import *
import matplotlib.pyplot as plt
plt.close('all')
options.display.mpl_style='default'
import matplotlib
try:
matplotlib.style.use('ggplot')
except AttributeError:
options.display.mpl_style = 'default'
from pandas.compat import lrange


Expand Down
8 changes: 6 additions & 2 deletions doc/source/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
np.set_printoptions(precision=4, suppress=True)
import matplotlib.pyplot as plt
plt.close('all')
options.display.mpl_style='default'
import matplotlib
try:
matplotlib.style.use('ggplot')
except AttributeError:
options.display.mpl_style = 'default'
from pandas.compat import zip

*****************************
Expand Down Expand Up @@ -346,7 +350,7 @@ A single group can be selected using ``GroupBy.get_group()``:
.. ipython:: python

grouped.get_group('bar')

Or for an object grouped on multiple columns:

.. ipython:: python
Expand Down
11 changes: 11 additions & 0 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,17 @@ should be taken instead.
df2.drop_duplicates(['a','b'])
df2.drop_duplicates(['a','b'], take_last=True)

An alternative way to drop duplicates on the index is ``.groupby(level=0)`` combined with ``first()`` or ``last()``.

.. ipython:: python

df3 = df2.set_index('b')
df3
df3.groupby(level=0).first()

# a bit more verbose
df3.reset_index().drop_duplicates(subset='b', take_last=False).set_index('b')

.. _indexing.dictionarylike:

Dictionary-like :meth:`~pandas.DataFrame.get` method
Expand Down
4 changes: 0 additions & 4 deletions doc/source/sparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import pandas.util.testing as tm
randn = np.random.randn
np.set_printoptions(precision=4, suppress=True)
import matplotlib.pyplot as plt
plt.close('all')
options.display.mpl_style='default'
options.display.max_rows = 15

**********************
Expand Down Expand Up @@ -222,4 +219,3 @@ row and columns coordinates of the matrix. Note that this will consume a signifi

ss_dense = SparseSeries.from_coo(A, dense_index=True)
ss_dense

10 changes: 7 additions & 3 deletions doc/source/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ We use the standard convention for referencing the matplotlib API:

import matplotlib.pyplot as plt

.. versionadded:: 0.11.0
The plots in this document are made using matplotlib's ``ggplot`` style (new in version 1.4):

The plots in this document are made using matplotlib's ``ggplot`` style (new in version 1.4).
If your version of matplotlib is 1.3 or lower, setting the ``display.mpl_style`` to ``'default'``
.. code-block:: python

import matplotlib
matplotlib.style.use('ggplot')

If your version of matplotlib is 1.3 or lower, you can set ``display.mpl_style`` to ``'default'``
with ``pd.options.display.mpl_style = 'default'``
to produce more appealing plots.
When set, matplotlib's ``rcParams`` are changed (globally!) to nicer-looking settings.
Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ What's New

These are new features and improvements of note in each release.

.. include:: whatsnew/v0.16.1.txt

.. include:: whatsnew/v0.16.0.txt

.. include:: whatsnew/v0.15.2.txt
Expand Down
50 changes: 40 additions & 10 deletions doc/source/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@
v0.16.1 (April ??, 2015)
------------------------

This is a minor bug-fix release from 0.16.0 and includes a small number of API changes, several new features,
enhancements, and performance improvements along with a large number of bug fixes. We recommend that all
users upgrade to this version.
This is a minor bug-fix release from 0.16.0 and includes a a large number of
bug fixes along several new features, enhancements, and performance improvements.
We recommend that all users upgrade to this version.

.. contents:: What's new in v0.16.1
:local:
:backlinks: none


.. _whatsnew_0161.enhancements:

Enhancements
~~~~~~~~~~~~





- :ref:`Enhancements <whatsnew_0161.enhancements>`
- :ref:`API Changes <whatsnew_0161.api>`
- :ref:`Performance Improvements <whatsnew_0161.performance>`
- :ref:`Bug Fixes <whatsnew_0161.bug_fixes>`

.. _whatsnew_0161.api:

API changes
~~~~~~~~~~~

.. _whatsnew_0161.enhancements:

Enhancements
~~~~~~~~~~~~




- Add support for separating years and quarters using dashes, for
example 2014-Q1. (:issue:`9688`)
Expand All @@ -30,7 +40,27 @@ Enhancements
Performance Improvements
~~~~~~~~~~~~~~~~~~~~~~~~






.. _whatsnew_0161.bug_fixes:

Bug Fixes
~~~~~~~~~





- Bug in ``transform`` causing length mismatch when null entries were present and a fast aggregator was being used (:issue:`9697`)








- Bug in ``Series.quantile`` on empty Series of type ``Datetime`` or ``Timedelta`` (:issue:`9675`)
20 changes: 13 additions & 7 deletions pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,20 @@ def get_col_type(dtype):
strcols = self._to_str_columns()

if self.index and isinstance(self.frame.index, MultiIndex):
clevels = self.frame.columns.nlevels
strcols.pop(0)
name = any(self.frame.columns.names)
for i, lev in enumerate(self.frame.index.levels):
lev2 = lev.format(name=name)
width = len(lev2[0])
lev3 = [' ' * width] * clevels + lev2
strcols.insert(i, lev3)


fmt = self._get_formatter('__index__')
fmt_index = self.frame.index.format(sparsify=self.sparsify,
adjoin=False,
names=True,
formatter=fmt)

for i, lev in enumerate(fmt_index):
width = len(lev[0])
lev2 = [width * ' ' if l == '' else l for l in lev]
lev2.insert(0, width * ' ')
strcols.insert(i, lev2)

if column_format is None:
dtypes = self.frame.dtypes.values
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2453,7 +2453,7 @@ def _transform_fast(self, func):
if isinstance(func, compat.string_types):
func = getattr(self,func)
values = func().values
counts = self.count().values
counts = self.size().values
values = np.repeat(values, com._ensure_platform_int(counts))

return self._set_result_index_ordered(Series(values))
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ def _maybe_box(self, func, dropna=False):
boxer = com.i8_boxer(self)

if len(values) == 0:
return boxer(iNaT)
return boxer(tslib.iNaT)

values = values.view('i8')
result = func(values)
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,19 @@ def test_transform_function_aliases(self):
expected = self.df.groupby('A')['C'].transform(np.mean)
assert_series_equal(result, expected)

def test_transform_length(self):
# GH 9697
df = pd.DataFrame({'col1':[1,1,2,2], 'col2':[1,2,3,np.nan]})
expected = pd.Series([3.0]*4)
def nsum(x):
return np.nansum(x)
results = [df.groupby('col1').transform(sum)['col2'],
df.groupby('col1')['col2'].transform(sum),
df.groupby('col1').transform(nsum)['col2'],
df.groupby('col1')['col2'].transform(nsum)]
for result in results:
assert_series_equal(result, expected)

def test_with_na(self):
index = Index(np.arange(10))

Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6837,6 +6837,11 @@ def test_repeat(self):
def test_unique_data_ownership(self):
# it works! #1807
Series(Series(["a", "c", "b"]).unique()).sort()

def test_datetime_timedelta_quantiles(self):
# covers #9694
self.assertTrue(pd.isnull(Series([],dtype='M8[ns]').quantile(.5)))
self.assertTrue(pd.isnull(Series([],dtype='m8[ns]').quantile(.5)))

if __name__ == '__main__':
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/tests/test_tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_repr(self):

# dateutil zone change (only matters for repr)
import dateutil
if dateutil.__version__ >= LooseVersion('2.3') and dateutil.__version__ <= LooseVersion('2.4'):
if dateutil.__version__ >= LooseVersion('2.3') and dateutil.__version__ <= LooseVersion('2.4.0'):
timezones = ['UTC', 'Asia/Tokyo', 'US/Eastern', 'dateutil/US/Pacific']
else:
timezones = ['UTC', 'Asia/Tokyo', 'US/Eastern', 'dateutil/America/Los_Angeles']
Expand Down