Skip to content

Commit e0fc211

Browse files
committed
Merge branch 'tuple-fix' of https://github.com/onesandzeroes/pandas into onesandzeroes-tuple-fix
Conflicts: doc/source/v0.14.1.txt
2 parents 4296c3a + 239ae6d commit e0fc211

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

doc/source/timeseries.rst

+7-6
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ the quarter end:
12441244
Time Zone Handling
12451245
------------------
12461246

1247-
Pandas provides rich support for working with timestamps in different time zones using ``pytz`` and ``dateutil`` libraries.
1247+
Pandas provides rich support for working with timestamps in different time zones using ``pytz`` and ``dateutil`` libraries.
12481248
``dateutil`` support is new [in 0.14.1] and currently only supported for fixed offset and tzfile zones. The default library is ``pytz``.
12491249
Support for ``dateutil`` is provided for compatibility with other applications e.g. if you use ``dateutil`` in other python packages.
12501250

@@ -1257,13 +1257,14 @@ By default, pandas objects are time zone unaware:
12571257
12581258
To supply the time zone, you can use the ``tz`` keyword to ``date_range`` and
12591259
other functions. Dateutil time zone strings are distinguished from ``pytz``
1260-
time zones by starting with ``dateutil/``. In ``pytz`` you can find a list of
1261-
common (and less common) time zones using ``from pytz import common_timezones, all_timezones``.
1262-
``dateutil`` uses the OS timezones so there isn't a fixed list available. For
1260+
time zones by starting with ``dateutil/``.
1261+
1262+
- In ``pytz`` you can find a list of common (and less common) time zones using ``from pytz import common_timezones, all_timezones``.
1263+
- ``dateutil`` uses the OS timezones so there isn't a fixed list available. For
12631264
common zones, the names are the same as ``pytz``.
12641265

12651266
.. ipython:: python
1266-
1267+
12671268
# pytz
12681269
rng_utc = date_range('3/6/2012 00:00', periods=10, freq='D', tz='UTC')
12691270
rng_utc.tz
@@ -1314,7 +1315,7 @@ tz-aware data to another time zone:
13141315
.. warning::
13151316
Be very wary of conversions between libraries as ``pytz`` and ``dateutil``
13161317
may have different definitions of the time zones. This is more of a problem for
1317-
unusual timezones than for 'standard' zones like ``US/Eastern``.
1318+
unusual timezones than for 'standard' zones like ``US/Eastern``.
13181319

13191320
Under the hood, all timestamps are stored in UTC. Scalar values from a
13201321
``DatetimeIndex`` with a time zone will have their fields (day, hour, minute)

doc/source/v0.14.1.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ Enhancements
6464

6565
.. ipython:: python
6666

67-
rng_utc_dateutil = date_range('3/6/2012 00:00', periods=10, freq='D',
67+
rng_utc_dateutil = date_range('3/6/2012 00:00',
68+
periods=10,
69+
freq='D',
6870
tz='dateutil/UTC')
6971
rng_utc_dateutil.tz
7072

@@ -114,3 +116,4 @@ Bug Fixes
114116
- Bug in ``CustomBusinessDay.apply`` raiases ``NameError`` when ``np.datetime64`` object is passed (:issue:`7196`)
115117
- Bug in ``MultiIndex.append``, ``concat`` and ``pivot_table`` don't preserve timezone (:issue:`6606`)
116118
- Bug in ``.loc`` with a list of indexers on a single-multi index level (that is not nested) (:issue:`7349`)
119+
- Bug in ``Series.map`` when mapping a dict with tuple keys of different lengths (:issue:`7333`)

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ def map_f(values, f):
19401940

19411941
if isinstance(arg, (dict, Series)):
19421942
if isinstance(arg, dict):
1943-
arg = self._constructor(arg)
1943+
arg = self._constructor(arg, index=arg.keys())
19441944

19451945
indexer = arg.index.get_indexer(values)
19461946
new_values = com.take_1d(arg.values, indexer)

pandas/tests/test_series.py

+19
Original file line numberDiff line numberDiff line change
@@ -4873,6 +4873,25 @@ def test_map_na_exclusion(self):
48734873
exp = s * 2
48744874
assert_series_equal(result, exp)
48754875

4876+
def test_map_dict_with_tuple_keys(self):
4877+
'''
4878+
Due to new MultiIndex-ing behaviour in v0.14.0,
4879+
dicts with tuple keys passed to map were being
4880+
converted to a multi-index, preventing tuple values
4881+
from being mapped properly.
4882+
'''
4883+
df = pd.DataFrame({'a': [(1,), (2,), (3, 4), (5, 6)]})
4884+
label_mappings = {
4885+
(1,): 'A',
4886+
(2,): 'B',
4887+
(3, 4): 'A',
4888+
(5, 6): 'B'
4889+
}
4890+
df['labels'] = df['a'].map(label_mappings)
4891+
df['expected_labels'] = pd.Series(['A', 'B', 'A', 'B'], index=df.index)
4892+
# All labels should be filled now
4893+
tm.assert_series_equal(df['labels'], df['expected_labels'])
4894+
48764895
def test_apply(self):
48774896
assert_series_equal(self.ts.apply(np.sqrt), np.sqrt(self.ts))
48784897

0 commit comments

Comments
 (0)