<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from io import StringIO
import pandas as pd

data = '''Date,Amount
10/30/2010,54
11/20/2010,53'''
df = pd.read_csv(StringIO(data), parse_dates=[0])

df.groupby([df.Date.dt.year, df.Date.dt.month]).mean()
"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">io</span> <span class="pl-k">import</span> <span class="pl-v">StringIO</span>
<span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s">'''Date,Amount</span>
<span class="pl-s">10/30/2010,54</span>
<span class="pl-s">11/20/2010,53'''</span>
<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_csv</span>(<span class="pl-v">StringIO</span>(<span class="pl-s1">data</span>), <span class="pl-s1">parse_dates</span><span class="pl-c1">=</span>[<span class="pl-c1">0</span>])

<span class="pl-s1">df</span>.<span class="pl-en">groupby</span>([<span class="pl-s1">df</span>.<span class="pl-v">Date</span>.<span class="pl-s1">dt</span>.<span class="pl-s1">year</span>, <span class="pl-s1">df</span>.<span class="pl-v">Date</span>.<span class="pl-s1">dt</span>.<span class="pl-s1">month</span>]).<span class="pl-en">mean</span>()</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">This worked prior to 0.23 and seems like a regression. I now get the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _cython_agg_blocks(self, how, alt, numeric_only, min_count)
   4017                 result, _ = self.grouper.aggregate(
-&gt; 4018                     block.values, how, axis=agg_axis, min_count=min_count)
   4019             except NotImplementedError:

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in aggregate(self, values, how, axis, min_count)
   2626         return self._cython_operation('aggregate', values, how, axis,
-&gt; 2627                                       min_count=min_count)
   2628 

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _cython_operation(self, kind, values, how, axis, min_count, **kwargs)
   2532                                           &quot;supported for the 'how' argument&quot;)
-&gt; 2533             out_shape = (self.ngroups,) + values.shape[1:]
   2534 

pandas/_libs/properties.pyx in pandas._libs.properties.CachedProperty.__get__()

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in ngroups(self)
   2361     def ngroups(self):
-&gt; 2362         return len(self.result_index)
   2363 

pandas/_libs/properties.pyx in pandas._libs.properties.CachedProperty.__get__()

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in result_index(self)
   2380                             verify_integrity=False,
-&gt; 2381                             names=self.names)
   2382         return result

~/.env/36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in __new__(cls, levels, labels, sortorder, names, dtype, copy, name, verify_integrity, _set_identity)
    231             # handles name validation
--&gt; 232             result._set_names(names)
    233 

~/.env/36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in _set_names(self, names, level, validate)
    694                         'level {}, is already used for level '
--&gt; 695                         '{}.'.format(name, l, used[name]))
    696 

ValueError: Duplicated level name: &quot;Date&quot;, assigned to level 1, is already used for level 0.

During handling of the above exception, another exception occurred:

UnboundLocalError                         Traceback (most recent call last)
~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in mean(self, *args, **kwargs)
   1305         try:
-&gt; 1306             return self._cython_agg_general('mean', **kwargs)
   1307         except GroupByError:

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _cython_agg_general(self, how, alt, numeric_only, min_count)
   3973         new_items, new_blocks = self._cython_agg_blocks(
-&gt; 3974             how, alt=alt, numeric_only=numeric_only, min_count=min_count)
   3975         return self._wrap_agged_blocks(new_items, new_blocks)

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _cython_agg_blocks(self, how, alt, numeric_only, min_count)
   4038                 # see if we can cast the block back to the original dtype
-&gt; 4039                 result = block._try_coerce_and_cast_result(result)
   4040                 newb = block.make_block(result)

UnboundLocalError: local variable 'result' referenced before assignment

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
&lt;ipython-input-13-4b644a75a9ce&gt; in &lt;module&gt;()
     10 df.dtypes
     11 
---&gt; 12 df.groupby([df.Date.dt.year, df.Date.dt.month]).mean()

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in mean(self, *args, **kwargs)
   1310             with _group_selection_context(self):
   1311                 f = lambda x: x.mean(axis=self.axis, **kwargs)
-&gt; 1312                 return self._python_agg_general(f)
   1313 
   1314     @Substitution(name='groupby')

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _python_agg_general(self, func, *args, **kwargs)
   1086                 output[name] = self._try_cast(values[mask], result)
   1087 
-&gt; 1088         return self._wrap_aggregated_output(output)
   1089 
   1090     def _wrap_applied_output(self, *args, **kwargs):

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _wrap_aggregated_output(self, output, names)
   4728             result = result._consolidate()
   4729         else:
-&gt; 4730             index = self.grouper.result_index
   4731             result = DataFrame(output, index=index, columns=output_keys)
   4732 

pandas/_libs/properties.pyx in pandas._libs.properties.CachedProperty.__get__()

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in result_index(self)
   2379                             labels=labels,
   2380                             verify_integrity=False,
-&gt; 2381                             names=self.names)
   2382         return result
   2383 

~/.env/36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in __new__(cls, levels, labels, sortorder, names, dtype, copy, name, verify_integrity, _set_identity)
    230         if names is not None:
    231             # handles name validation
--&gt; 232             result._set_names(names)
    233 
    234         if sortorder is not None:

~/.env/36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in _set_names(self, names, level, validate)
    693                         'Duplicated level name: &quot;{}&quot;, assigned to '
    694                         'level {}, is already used for level '
--&gt; 695                         '{}.'.format(name, l, used[name]))
    696 
    697             self.levels[l].rename(name, inplace=True)

ValueError: Duplicated level name: &quot;Date&quot;, assigned to level 1, is already used for level 0.
"><pre class="notranslate"><code class="notranslate">
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _cython_agg_blocks(self, how, alt, numeric_only, min_count)
   4017                 result, _ = self.grouper.aggregate(
-&gt; 4018                     block.values, how, axis=agg_axis, min_count=min_count)
   4019             except NotImplementedError:

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in aggregate(self, values, how, axis, min_count)
   2626         return self._cython_operation('aggregate', values, how, axis,
-&gt; 2627                                       min_count=min_count)
   2628 

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _cython_operation(self, kind, values, how, axis, min_count, **kwargs)
   2532                                           "supported for the 'how' argument")
-&gt; 2533             out_shape = (self.ngroups,) + values.shape[1:]
   2534 

pandas/_libs/properties.pyx in pandas._libs.properties.CachedProperty.__get__()

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in ngroups(self)
   2361     def ngroups(self):
-&gt; 2362         return len(self.result_index)
   2363 

pandas/_libs/properties.pyx in pandas._libs.properties.CachedProperty.__get__()

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in result_index(self)
   2380                             verify_integrity=False,
-&gt; 2381                             names=self.names)
   2382         return result

~/.env/36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in __new__(cls, levels, labels, sortorder, names, dtype, copy, name, verify_integrity, _set_identity)
    231             # handles name validation
--&gt; 232             result._set_names(names)
    233 

~/.env/36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in _set_names(self, names, level, validate)
    694                         'level {}, is already used for level '
--&gt; 695                         '{}.'.format(name, l, used[name]))
    696 

ValueError: Duplicated level name: "Date", assigned to level 1, is already used for level 0.

During handling of the above exception, another exception occurred:

UnboundLocalError                         Traceback (most recent call last)
~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in mean(self, *args, **kwargs)
   1305         try:
-&gt; 1306             return self._cython_agg_general('mean', **kwargs)
   1307         except GroupByError:

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _cython_agg_general(self, how, alt, numeric_only, min_count)
   3973         new_items, new_blocks = self._cython_agg_blocks(
-&gt; 3974             how, alt=alt, numeric_only=numeric_only, min_count=min_count)
   3975         return self._wrap_agged_blocks(new_items, new_blocks)

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _cython_agg_blocks(self, how, alt, numeric_only, min_count)
   4038                 # see if we can cast the block back to the original dtype
-&gt; 4039                 result = block._try_coerce_and_cast_result(result)
   4040                 newb = block.make_block(result)

UnboundLocalError: local variable 'result' referenced before assignment

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
&lt;ipython-input-13-4b644a75a9ce&gt; in &lt;module&gt;()
     10 df.dtypes
     11 
---&gt; 12 df.groupby([df.Date.dt.year, df.Date.dt.month]).mean()

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in mean(self, *args, **kwargs)
   1310             with _group_selection_context(self):
   1311                 f = lambda x: x.mean(axis=self.axis, **kwargs)
-&gt; 1312                 return self._python_agg_general(f)
   1313 
   1314     @Substitution(name='groupby')

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _python_agg_general(self, func, *args, **kwargs)
   1086                 output[name] = self._try_cast(values[mask], result)
   1087 
-&gt; 1088         return self._wrap_aggregated_output(output)
   1089 
   1090     def _wrap_applied_output(self, *args, **kwargs):

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in _wrap_aggregated_output(self, output, names)
   4728             result = result._consolidate()
   4729         else:
-&gt; 4730             index = self.grouper.result_index
   4731             result = DataFrame(output, index=index, columns=output_keys)
   4732 

pandas/_libs/properties.pyx in pandas._libs.properties.CachedProperty.__get__()

~/.env/36/lib/python3.6/site-packages/pandas/core/groupby/groupby.py in result_index(self)
   2379                             labels=labels,
   2380                             verify_integrity=False,
-&gt; 2381                             names=self.names)
   2382         return result
   2383 

~/.env/36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in __new__(cls, levels, labels, sortorder, names, dtype, copy, name, verify_integrity, _set_identity)
    230         if names is not None:
    231             # handles name validation
--&gt; 232             result._set_names(names)
    233 
    234         if sortorder is not None:

~/.env/36/lib/python3.6/site-packages/pandas/core/indexes/multi.py in _set_names(self, names, level, validate)
    693                         'Duplicated level name: "{}", assigned to '
    694                         'level {}, is already used for level '
--&gt; 695                         '{}.'.format(name, l, used[name]))
    696 
    697             self.levels[l].rename(name, inplace=True)

ValueError: Duplicated level name: "Date", assigned to level 1, is already used for level 0.

</code></pre></div>
<h4 dir="auto">Expected Output</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="           Amount
Date Date        
2010 10        54
     11        53"><pre class="notranslate"><code class="notranslate">           Amount
Date Date        
2010 10        54
     11        53
</code></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Darwin
OS-release: 16.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
<p dir="auto">pandas: 0.23.0<br>
pytest: 3.0.6<br>
pip: 10.0.1<br>
setuptools: 39.2.0<br>
Cython: 0.27.3<br>
numpy: 1.14.3<br>
scipy: 1.1.0<br>
pyarrow: None<br>
xarray: None<br>
IPython: 6.2.1<br>
sphinx: 1.7.5<br>
patsy: 0.5.0<br>
dateutil: 2.7.3<br>
pytz: 2018.4<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: 2.2.2<br>
openpyxl: 2.4.7<br>
xlrd: 1.0.0<br>
xlwt: 1.2.0<br>
xlsxwriter: None<br>
lxml: 3.7.2<br>
bs4: 4.6.0<br>
html5lib: 0.9999999<br>
sqlalchemy: 1.2.5<br>
pymysql: None<br>
psycopg2: 2.7.4 (dt dec pq3 ext lo64)<br>
jinja2: 2.10<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.date_range('2018-10-23', '2018-11-06', freq='7D', tz='Europe/Paris')
DatetimeIndex(['2018-10-23 00:00:00+02:00', '2018-10-29 23:00:00+01:00', '2018-11-05 23:00:00+01:00'], dtype='datetime64[ns, Europe/Paris]', freq='7D')

&gt;&gt;&gt; pd.date_range('2018-03-25', '2018-04-09', freq='7D', tz='Europe/Paris')
DatetimeIndex(['2018-03-25 00:00:00+01:00', '2018-04-01 01:00:00+02:00', '2018-04-08 01:00:00+02:00'], dtype='datetime64[ns, Europe/Paris]', freq='7D')"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'2018-10-23'</span>, <span class="pl-s">'2018-11-06'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'7D'</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'Europe/Paris'</span>)
<span class="pl-v">DatetimeIndex</span>([<span class="pl-s">'2018-10-23 00:00:00+02:00'</span>, <span class="pl-s">'2018-10-29 23:00:00+01:00'</span>, <span class="pl-s">'2018-11-05 23:00:00+01:00'</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'datetime64[ns, Europe/Paris]'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'7D'</span>)

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'2018-03-25'</span>, <span class="pl-s">'2018-04-09'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'7D'</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'Europe/Paris'</span>)
<span class="pl-v">DatetimeIndex</span>([<span class="pl-s">'2018-03-25 00:00:00+01:00'</span>, <span class="pl-s">'2018-04-01 01:00:00+02:00'</span>, <span class="pl-s">'2018-04-08 01:00:00+02:00'</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'datetime64[ns, Europe/Paris]'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'7D'</span>)</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">It seems that the <code class="notranslate">D</code> frequency is somewhat broken around DST dates. The code above gives the same result as <code class="notranslate">pd.date_range(..., freq='168H', tz='Europe/Paris')</code>, but it should be different.</p>
<h4 dir="auto">Expected Output</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.date_range('2018-10-23', '2018-11-06', freq='7D', tz='Europe/Paris')
DatetimeIndex(['2018-10-23 00:00:00+02:00', '2018-10-30 00:00:00+01:00', '2018-11-06 00:00:00+01:00'], dtype='datetime64[ns, Europe/Paris]', freq='7D')

&gt;&gt;&gt; pd.date_range('2018-03-25', '2018-04-09', freq='7D', tz='Europe/Paris')
DatetimeIndex(['2018-03-25 00:00:00+01:00', '2018-04-01 00:00:00+02:00', '2018-04-08 00:00:00+02:00'], dtype='datetime64[ns, Europe/Paris]', freq='7D')"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'2018-10-23'</span>, <span class="pl-s">'2018-11-06'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'7D'</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'Europe/Paris'</span>)
<span class="pl-v">DatetimeIndex</span>([<span class="pl-s">'2018-10-23 00:00:00+02:00'</span>, <span class="pl-s">'2018-10-30 00:00:00+01:00'</span>, <span class="pl-s">'2018-11-06 00:00:00+01:00'</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'datetime64[ns, Europe/Paris]'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'7D'</span>)

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'2018-03-25'</span>, <span class="pl-s">'2018-04-09'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'7D'</span>, <span class="pl-s1">tz</span><span class="pl-c1">=</span><span class="pl-s">'Europe/Paris'</span>)
<span class="pl-v">DatetimeIndex</span>([<span class="pl-s">'2018-03-25 00:00:00+01:00'</span>, <span class="pl-s">'2018-04-01 00:00:00+02:00'</span>, <span class="pl-s">'2018-04-08 00:00:00+02:00'</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'datetime64[ns, Europe/Paris]'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'7D'</span>)</pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.6.5.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 3.16.0-5-amd64<br>
machine: x86_64<br>
processor:<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: fr_FR.UTF-8<br>
LOCALE: fr_FR.UTF-8</p>
<p dir="auto">pandas: 0.22.0<br>
pytest: None<br>
pip: 9.0.3<br>
setuptools: 39.0.1<br>
Cython: None<br>
numpy: 1.14.2<br>
scipy: 1.0.1<br>
pyarrow: None<br>
xarray: None<br>
IPython: 6.3.0<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.7.2<br>
pytz: 2018.3<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: 2.2.2<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: None<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>