Skip to content

Commit 2dc2ce2

Browse files
committed
Merge branch 'upstream' into pyx-diff
2 parents 81cbb7b + e8e0aae commit 2dc2ce2

File tree

7 files changed

+71
-18
lines changed

7 files changed

+71
-18
lines changed

doc/source/basics.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,14 +1159,17 @@ mapping (a dict or Series) or an arbitrary function.
11591159
s.rename(str.upper)
11601160
11611161
If you pass a function, it must return a value when called with any of the
1162-
labels (and must produce a set of unique values). But if you pass a dict or
1163-
Series, it need only contain a subset of the labels as keys:
1162+
labels (and must produce a set of unique values). A dict or
1163+
Series can also be used:
11641164

11651165
.. ipython:: python
11661166
11671167
df.rename(columns={'one' : 'foo', 'two' : 'bar'},
11681168
index={'a' : 'apple', 'b' : 'banana', 'd' : 'durian'})
11691169
1170+
If the mapping doesn't include a column/index label, it isn't renamed. Also
1171+
extra labels in the mapping don't throw an error.
1172+
11701173
The :meth:`~DataFrame.rename` method also provides an ``inplace`` named
11711174
parameter that is by default ``False`` and copies the underlying data. Pass
11721175
``inplace=True`` to rename the data in place.

doc/source/ecosystem.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,16 @@ more advanced types of plots then those offered by pandas.
7777
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7878

7979
The `Vincent <https://github.com/wrobstory/vincent>`__ project leverages `Vega <https://github.com/trifacta/vega>`__
80-
(that in turn, leverages `d3 <http://d3js.org/>`__) to create plots . It has great support
81-
for pandas data objects.
80+
(that in turn, leverages `d3 <http://d3js.org/>`__) to create
81+
plots. Although functional, as of Summer 2016 the Vincent project has not been updated
82+
in over two years and is `unlikely to receive further updates <https://github.com/wrobstory/vincent#2015-08-12-update>`__.
83+
84+
`IPython Vega <https://github.com/vega/ipyvega>`__
85+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86+
87+
Like Vincent, the `IPython Vega <https://github.com/vega/ipyvega>`__ project leverages `Vega
88+
<https://github.com/trifacta/vega>`__ to create plots, but primarily
89+
targets the IPython Notebook environment.
8290

8391
`Plotly <https://plot.ly/python>`__
8492
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/source/groupby.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,23 @@ Regroup columns of a DataFrame according to their sum, and sum the aggregated on
10151015
df
10161016
df.groupby(df.sum(), axis=1).sum()
10171017
1018+
Groupby by Indexer to 'resample' data
1019+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1020+
1021+
Resampling produces new hypothetical samples(resamples) from already existing observed data or from a model that generates data. These new samples are similar to the pre-existing samples.
1022+
1023+
In order to resample to work on indices that are non-datetimelike , the following procedure can be utilized.
1024+
1025+
In the following examples, **df.index // 5** returns a binary array which is used to determine what get's selected for the groupby operation.
1026+
1027+
.. note:: The below example shows how we can downsample by consolidation of samples into fewer samples. Here by using **df.index // 5**, we are aggregating the samples in bins. By applying **std()** function, we aggregate the information contained in many samples into a small subset of values which is their standard deviation thereby reducing the number of samples.
1028+
1029+
.. ipython:: python
1030+
1031+
df = pd.DataFrame(np.random.randn(10,2))
1032+
df
1033+
df.index // 5
1034+
df.groupby(df.index // 5).std()
10181035
10191036
Returning a Series to propagate names
10201037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/source/whatsnew/v0.18.1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ Bug Fixes
658658
- Bug in ``CategoricalIndex.get_loc`` returns different result from regular ``Index`` (:issue:`12531`)
659659
- Bug in ``PeriodIndex.resample`` where name not propagated (:issue:`12769`)
660660

661-
661+
- Bug in ``date_range`` ``closed`` keyword and timezones (:issue:`12684`).
662662

663663
- Bug in ``pd.concat`` raises ``AttributeError`` when input data contains tz-aware datetime and timedelta (:issue:`12620`)
664664
- Bug in ``pd.concat`` did not handle empty ``Series`` properly (:issue:`11082`)

pandas/core/generic.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ def swaplevel(self, i=-2, j=-1, axis=0):
555555
_shared_docs['rename'] = """
556556
Alter axes input function or functions. Function / dict values must be
557557
unique (1-to-1). Labels not contained in a dict / Series will be left
558-
as-is. Alternatively, change ``Series.name`` with a scalar
559-
value (Series only).
558+
as-is. Extra labels listed don't throw an error. Alternatively, change
559+
``Series.name`` with a scalar value (Series only).
560560
561561
Parameters
562562
----------
@@ -611,6 +611,11 @@ def swaplevel(self, i=-2, j=-1, axis=0):
611611
0 1 4
612612
1 2 5
613613
2 3 6
614+
>>> df.rename(index=str, columns={"A": "a", "C": "c"})
615+
a B
616+
0 1 4
617+
1 2 5
618+
2 3 6
614619
"""
615620

616621
@Appender(_shared_docs['rename'] % dict(axes='axes keywords for this'

pandas/tseries/index.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,13 @@ def _generate(cls, start, end, periods, name, offset,
541541
ambiguous=ambiguous)
542542
index = index.view(_NS_DTYPE)
543543

544+
# index is localized datetime64 array -> have to convert
545+
# start/end as well to compare
546+
if start is not None:
547+
start = start.tz_localize(tz).asm8
548+
if end is not None:
549+
end = end.tz_localize(tz).asm8
550+
544551
if not left_closed and len(index) and index[0] == start:
545552
index = index[1:]
546553
if not right_closed and len(index) and index[-1] == end:

pandas/tseries/tests/test_daterange.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def test_range_closed(self):
485485
begin = datetime(2011, 1, 1)
486486
end = datetime(2014, 1, 1)
487487

488-
for freq in ["3D", "2M", "7W", "3H", "A"]:
488+
for freq in ["1D", "3D", "2M", "7W", "3H", "A"]:
489489
closed = date_range(begin, end, closed=None, freq=freq)
490490
left = date_range(begin, end, closed="left", freq=freq)
491491
right = date_range(begin, end, closed="right", freq=freq)
@@ -501,11 +501,11 @@ def test_range_closed(self):
501501
self.assert_index_equal(expected_right, right)
502502

503503
def test_range_closed_with_tz_aware_start_end(self):
504-
# GH12409
504+
# GH12409, GH12684
505505
begin = Timestamp('2011/1/1', tz='US/Eastern')
506506
end = Timestamp('2014/1/1', tz='US/Eastern')
507507

508-
for freq in ["3D", "2M", "7W", "3H", "A"]:
508+
for freq in ["1D", "3D", "2M", "7W", "3H", "A"]:
509509
closed = date_range(begin, end, closed=None, freq=freq)
510510
left = date_range(begin, end, closed="left", freq=freq)
511511
right = date_range(begin, end, closed="right", freq=freq)
@@ -520,15 +520,28 @@ def test_range_closed_with_tz_aware_start_end(self):
520520
self.assert_index_equal(expected_left, left)
521521
self.assert_index_equal(expected_right, right)
522522

523-
# test with default frequency, UTC
524-
begin = Timestamp('2011/1/1', tz='UTC')
525-
end = Timestamp('2014/1/1', tz='UTC')
523+
begin = Timestamp('2011/1/1')
524+
end = Timestamp('2014/1/1')
525+
begintz = Timestamp('2011/1/1', tz='US/Eastern')
526+
endtz = Timestamp('2014/1/1', tz='US/Eastern')
527+
528+
for freq in ["1D", "3D", "2M", "7W", "3H", "A"]:
529+
closed = date_range(begin, end, closed=None, freq=freq,
530+
tz='US/Eastern')
531+
left = date_range(begin, end, closed="left", freq=freq,
532+
tz='US/Eastern')
533+
right = date_range(begin, end, closed="right", freq=freq,
534+
tz='US/Eastern')
535+
expected_left = left
536+
expected_right = right
526537

527-
intervals = ['left', 'right', None]
528-
for i in intervals:
529-
result = date_range(start=begin, end=end, closed=i)
530-
self.assertEqual(result[0], begin)
531-
self.assertEqual(result[-1], end)
538+
if endtz == closed[-1]:
539+
expected_left = closed[:-1]
540+
if begintz == closed[0]:
541+
expected_right = closed[1:]
542+
543+
self.assert_index_equal(expected_left, left)
544+
self.assert_index_equal(expected_right, right)
532545

533546
def test_range_closed_boundary(self):
534547
# GH 11804

0 commit comments

Comments
 (0)