# Buggy code
def nunique(self, dropna=True):
    """
    Return DataFrame with number of distinct observations per group for
    each column.

    .. versionadded:: 0.20.0

    Parameters
    ----------
    dropna : boolean, default True
        Don't include NaN in the counts.

    Returns
    -------
    nunique: DataFrame

    Examples
    --------
    >>> df = pd.DataFrame({'id': ['spam', 'egg', 'egg', 'spam',
    ...                           'ham', 'ham'],
    ...                    'value1': [1, 5, 5, 2, 5, 5],
    ...                    'value2': list('abbaxy')})
    >>> df
         id  value1 value2
    0  spam       1      a
    1   egg       5      b
    2   egg       5      b
    3  spam       2      a
    4   ham       5      x
    5   ham       5      y

    >>> df.groupby('id').nunique()
        id  value1  value2
    id
    egg    1       1       1
    ham    1       1       2
    spam   1       2       1

    # check for rows with the same id but conflicting values
    >>> df.groupby('id').filter(lambda g: (g.nunique() > 1).any())
         id  value1 value2
    0  spam       1      a
    3  spam       2      a
    4   ham       5      x
    5   ham       5      y
    """

    obj = self._selected_obj

    def groupby_series(obj, col=None):
        return SeriesGroupBy(obj, selection=col, grouper=self.grouper).nunique(
            dropna=dropna
        )

    if isinstance(obj, Series):
        results = groupby_series(obj)
    else:
        from pandas.core.reshape.concat import concat

        results = [groupby_series(obj[col], col) for col in obj.columns]
        results = concat(results, axis=1)

    if not self.as_index:
        results.index = ibase.default_index(len(results))
    return results


# Traceback (KeyError)
import pandas as pd
pd.show_versions()
Backend TkAgg is interactive backend. Turning interactive mode on.
Matplotlib support failed
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\183.3647.8\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 23, in do_import
succeeded = activate_func()
File "C:\Users\Admin\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\183.3647.8\helpers\pydev\pydev_ipython\matplotlibtools.py", line 141, in activate_pylab
pylab = sys.modules['pylab']
KeyError: 'pylab'
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.23.4
pytest: 3.8.2
pip: 18.1
setuptools: 40.4.3
Cython: 0.28.5
numpy: 1.15.1
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.0.1
sphinx: 1.8.1
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.0
openpyxl: 2.5.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.1.1
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.12
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

# Fixed code
def nunique(self, dropna=True):
    """
    Return DataFrame with number of distinct observations per group for
    each column.

    .. versionadded:: 0.20.0

    Parameters
    ----------
    dropna : boolean, default True
        Don't include NaN in the counts.

    Returns
    -------
    nunique: DataFrame

    Examples
    --------
    >>> df = pd.DataFrame({'id': ['spam', 'egg', 'egg', 'spam',
    ...                           'ham', 'ham'],
    ...                    'value1': [1, 5, 5, 2, 5, 5],
    ...                    'value2': list('abbaxy')})
    >>> df
         id  value1 value2
    0  spam       1      a
    1   egg       5      b
    2   egg       5      b
    3  spam       2      a
    4   ham       5      x
    5   ham       5      y

    >>> df.groupby('id').nunique()
        id  value1  value2
    id
    egg    1       1       1
    ham    1       1       2
    spam   1       2       1

    # check for rows with the same id but conflicting values
    >>> df.groupby('id').filter(lambda g: (g.nunique() > 1).any())
         id  value1 value2
    0  spam       1      a
    3  spam       2      a
    4   ham       5      x
    5   ham       5      y
    """

    obj = self._selected_obj

    def groupby_series(obj, col=None):
        return SeriesGroupBy(obj, selection=col, grouper=self.grouper).nunique(
            dropna=dropna
        )

    if isinstance(obj, Series):
        results = groupby_series(obj)
    else:
        from pandas.core.reshape.concat import concat

        results = [groupby_series(obj[col], col) for col in obj.columns]
        results = concat(results, axis=1)
        results.columns.names = obj.columns.names

    if not self.as_index:
        results.index = ibase.default_index(len(results))
    return results