Skip to content

Commit bf829c3

Browse files
committed
Merge remote-tracking branch 'upstream/master' into pd.array
2 parents 000967d + 9f29f88 commit bf829c3

File tree

5 files changed

+355
-357
lines changed

5 files changed

+355
-357
lines changed

doc/source/whatsnew/v0.22.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ sum and ``1`` for product.
137137
.. code-block:: ipython
138138
139139
In [11]: s = pd.Series([1, 1, np.nan, np.nan],
140-
...: index=pd.date_range('2017', periods=4))
141-
...: s
140+
....: index=pd.date_range('2017', periods=4))
141+
....: s
142142
Out[11]:
143143
2017-01-01 1.0
144144
2017-01-02 1.0

doc/source/whatsnew/v0.23.0.rst

+29-24
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ A ``DataFrame`` can now be written to and subsequently read back via JSON while
5353
.. ipython:: python
5454
5555
df = pd.DataFrame({'foo': [1, 2, 3, 4],
56-
'bar': ['a', 'b', 'c', 'd'],
57-
'baz': pd.date_range('2018-01-01', freq='d', periods=4),
58-
'qux': pd.Categorical(['a', 'b', 'c', 'c'])
59-
}, index=pd.Index(range(4), name='idx'))
56+
'bar': ['a', 'b', 'c', 'd'],
57+
'baz': pd.date_range('2018-01-01', freq='d', periods=4),
58+
'qux': pd.Categorical(['a', 'b', 'c', 'c'])},
59+
index=pd.Index(range(4), name='idx'))
6060
df
6161
df.dtypes
6262
df.to_json('test.json', orient='table')
@@ -97,7 +97,7 @@ The :func:`DataFrame.assign` now accepts dependent keyword arguments for python
9797
9898
df = pd.DataFrame({'A': [1, 2, 3]})
9999
df
100-
df.assign(B=df.A, C=lambda x:x['A']+ x['B'])
100+
df.assign(B=df.A, C=lambda x: x['A'] + x['B'])
101101
102102
.. warning::
103103

@@ -122,7 +122,7 @@ The :func:`DataFrame.assign` now accepts dependent keyword arguments for python
122122

123123
.. ipython:: python
124124
125-
df.assign(A=df.A+1, C= lambda df: df.A* -1)
125+
df.assign(A=df.A + 1, C=lambda df: df.A * -1)
126126
127127
128128
@@ -284,7 +284,7 @@ For pivotting operations, this behavior is *already* controlled by the ``dropna`
284284
categories=["a", "b", "z"], ordered=True)
285285
cat2 = pd.Categorical(["c", "d", "c", "d"],
286286
categories=["c", "d", "y"], ordered=True)
287-
df = DataFrame({"A": cat1, "B": cat2, "values": [1, 2, 3, 4]})
287+
df = pd.DataFrame({"A": cat1, "B": cat2, "values": [1, 2, 3, 4]})
288288
df
289289
290290
.. ipython:: python
@@ -336,7 +336,8 @@ outside the existing valid values while preserving those inside. (:issue:`16284
336336

337337
.. ipython:: python
338338
339-
ser = pd.Series([np.nan, np.nan, 5, np.nan, np.nan, np.nan, 13, np.nan, np.nan])
339+
ser = pd.Series([np.nan, np.nan, 5, np.nan, np.nan,
340+
np.nan, 13, np.nan, np.nan])
340341
ser
341342
342343
Fill one consecutive inside value in both directions
@@ -600,15 +601,16 @@ Previous Behavior (and current behavior if on Python < 3.6):
600601

601602
.. code-block:: ipython
602603
603-
pd.Series({'Income': 2000,
604-
'Expenses': -1500,
605-
'Taxes': -200,
606-
'Net result': 300})
607-
Expenses -1500
608-
Income 2000
609-
Net result 300
610-
Taxes -200
611-
dtype: int64
604+
In [16]: pd.Series({'Income': 2000,
605+
....: 'Expenses': -1500,
606+
....: 'Taxes': -200,
607+
....: 'Net result': 300})
608+
Out[16]:
609+
Expenses -1500
610+
Income 2000
611+
Net result 300
612+
Taxes -200
613+
dtype: int64
612614
613615
Note the Series above is ordered alphabetically by the index values.
614616

@@ -696,7 +698,8 @@ where a list-like (e.g. ``tuple`` or ``list`` is returned) (:issue:`16353`, :iss
696698

697699
.. ipython:: python
698700
699-
df = pd.DataFrame(np.tile(np.arange(3), 6).reshape(6, -1) + 1, columns=['A', 'B', 'C'])
701+
df = pd.DataFrame(np.tile(np.arange(3), 6).reshape(6, -1) + 1,
702+
columns=['A', 'B', 'C'])
700703
df
701704
702705
Previous Behavior: if the returned shape happened to match the length of original columns, this would return a ``DataFrame``.
@@ -750,7 +753,7 @@ Returning a ``Series`` allows one to control the exact return structure and colu
750753

751754
.. ipython:: python
752755
753-
df.apply(lambda x: Series([1, 2, 3], index=['D', 'E', 'F']), axis=1)
756+
df.apply(lambda x: pd.Series([1, 2, 3], index=['D', 'E', 'F']), axis=1)
754757
755758
.. _whatsnew_0230.api_breaking.concat:
756759

@@ -825,10 +828,12 @@ Current Behavior:
825828
.. ipython:: python
826829
827830
index = pd.Int64Index([-1, 0, 1])
828-
# division by zero gives -infinity where negative, +infinity where positive, and NaN for 0 / 0
831+
# division by zero gives -infinity where negative,
832+
# +infinity where positive, and NaN for 0 / 0
829833
index / 0
830834
831-
# The result of division by zero should not depend on whether the zero is int or float
835+
# The result of division by zero should not depend on
836+
# whether the zero is int or float
832837
index / 0.0
833838
834839
index = pd.UInt64Index([0, 1])
@@ -853,7 +858,7 @@ Previous Behavior:
853858
854859
In [1]: s = pd.Series(['number 10', '12 eggs'])
855860
856-
In [2]: extracted = s.str.extract('.*(\d\d).*')
861+
In [2]: extracted = s.str.extract(r'.*(\d\d).*')
857862
858863
In [3]: extracted
859864
Out [3]:
@@ -870,7 +875,7 @@ New Behavior:
870875
.. ipython:: python
871876
872877
s = pd.Series(['number 10', '12 eggs'])
873-
extracted = s.str.extract('.*(\d\d).*')
878+
extracted = s.str.extract(r'.*(\d\d).*')
874879
extracted
875880
type(extracted)
876881
@@ -879,7 +884,7 @@ To restore previous behavior, simply set ``expand`` to ``False``:
879884
.. ipython:: python
880885
881886
s = pd.Series(['number 10', '12 eggs'])
882-
extracted = s.str.extract('.*(\d\d).*', expand=False)
887+
extracted = s.str.extract(r'.*(\d\d).*', expand=False)
883888
extracted
884889
type(extracted)
885890

doc/source/whatsnew/v0.24.0.rst

+42-48
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ convenient way to apply users' predefined styling functions, and can help reduce
274274

275275
.. ipython:: python
276276
277-
df = pandas.DataFrame({'N': [1250, 1500, 1750], 'X': [0.25, 0.35, 0.50]})
277+
df = pd.DataFrame({'N': [1250, 1500, 1750], 'X': [0.25, 0.35, 0.50]})
278278
279279
def format_and_align(styler):
280280
return (styler.format({'N': '{:,}', 'X': '{:.1%}'})
@@ -304,8 +304,7 @@ See the :ref:`Merge, join, and concatenate
304304
305305
306306
left = pd.DataFrame({'A': ['A0', 'A1', 'A2'],
307-
'B': ['B0', 'B1', 'B2']},
308-
index=index_left)
307+
'B': ['B0', 'B1', 'B2']}, index=index_left)
309308
310309
311310
index_right = pd.MultiIndex.from_tuples([('K0', 'Y0'), ('K1', 'Y1'),
@@ -314,11 +313,9 @@ See the :ref:`Merge, join, and concatenate
314313
315314
316315
right = pd.DataFrame({'C': ['C0', 'C1', 'C2', 'C3'],
317-
'D': ['D0', 'D1', 'D2', 'D3']},
318-
index=index_right)
316+
'D': ['D0', 'D1', 'D2', 'D3']}, index=index_right)
319317
320-
321-
left.join(right)
318+
left.join(right)
322319
323320
For earlier versions this can be done using the following.
324321

@@ -463,26 +460,26 @@ Previous Behavior on Windows:
463460

464461
.. code-block:: ipython
465462
466-
In [1]: data = pd.DataFrame({
467-
...: "string_with_lf": ["a\nbc"],
468-
...: "string_with_crlf": ["a\r\nbc"]
469-
...: })
463+
In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
464+
...: "string_with_crlf": ["a\r\nbc"]})
470465
471-
In [2]: # When passing file PATH to to_csv, line_terminator does not work, and csv is saved with '\r\n'.
472-
...: # Also, this converts all '\n's in the data to '\r\n'.
473-
...: data.to_csv("test.csv", index=False, line_terminator='\n')
466+
In [2]: # When passing file PATH to to_csv,
467+
...: # line_terminator does not work, and csv is saved with '\r\n'.
468+
...: # Also, this converts all '\n's in the data to '\r\n'.
469+
...: data.to_csv("test.csv", index=False, line_terminator='\n')
474470
475471
In [3]: with open("test.csv", mode='rb') as f:
476-
...: print(f.read())
477-
b'string_with_lf,string_with_crlf\r\n"a\r\nbc","a\r\r\nbc"\r\n'
472+
...: print(f.read())
473+
Out[3]: b'string_with_lf,string_with_crlf\r\n"a\r\nbc","a\r\r\nbc"\r\n'
478474
479-
In [4]: # When passing file OBJECT with newline option to to_csv, line_terminator works.
480-
...: with open("test2.csv", mode='w', newline='\n') as f:
481-
...: data.to_csv(f, index=False, line_terminator='\n')
475+
In [4]: # When passing file OBJECT with newline option to
476+
...: # to_csv, line_terminator works.
477+
...: with open("test2.csv", mode='w', newline='\n') as f:
478+
...: data.to_csv(f, index=False, line_terminator='\n')
482479
483480
In [5]: with open("test2.csv", mode='rb') as f:
484-
...: print(f.read())
485-
b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
481+
...: print(f.read())
482+
Out[5]: b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
486483
487484
488485
New Behavior on Windows:
@@ -493,16 +490,14 @@ New Behavior on Windows:
493490

494491
.. code-block:: ipython
495492
496-
In [1]: data = pd.DataFrame({
497-
...: "string_with_lf": ["a\nbc"],
498-
...: "string_with_crlf": ["a\r\nbc"]
499-
...: })
493+
In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
494+
...: "string_with_crlf": ["a\r\nbc"]})
500495
501496
In [2]: data.to_csv("test.csv", index=False, line_terminator='\n')
502497
503498
In [3]: with open("test.csv", mode='rb') as f:
504-
...: print(f.read())
505-
b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
499+
...: print(f.read())
500+
Out[3]: b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
506501
507502
508503
- On Windows, the value of ``os.linesep`` is ``'\r\n'``,
@@ -511,34 +506,30 @@ New Behavior on Windows:
511506

512507
.. code-block:: ipython
513508
514-
In [1]: data = pd.DataFrame({
515-
...: "string_with_lf": ["a\nbc"],
516-
...: "string_with_crlf": ["a\r\nbc"]
517-
...: })
509+
In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
510+
...: "string_with_crlf": ["a\r\nbc"]})
518511
519512
In [2]: data.to_csv("test.csv", index=False)
520513
521514
In [3]: with open("test.csv", mode='rb') as f:
522-
...: print(f.read())
523-
b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
515+
...: print(f.read())
516+
Out[3]: b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
524517
525518
526519
- For files objects, specifying ``newline`` is not sufficient to set the line terminator.
527520
You must pass in the ``line_terminator`` explicitly, even in this case.
528521

529522
.. code-block:: ipython
530523
531-
In [1]: data = pd.DataFrame({
532-
...: "string_with_lf": ["a\nbc"],
533-
...: "string_with_crlf": ["a\r\nbc"]
534-
...: })
524+
In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
525+
...: "string_with_crlf": ["a\r\nbc"]})
535526
536527
In [2]: with open("test2.csv", mode='w', newline='\n') as f:
537-
...: data.to_csv(f, index=False)
528+
...: data.to_csv(f, index=False)
538529
539530
In [3]: with open("test2.csv", mode='rb') as f:
540-
...: print(f.read())
541-
b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
531+
...: print(f.read())
532+
Out[3]: b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
542533
543534
.. _whatsnew_0240.api.timezone_offset_parsing:
544535

@@ -585,7 +576,8 @@ Parsing datetime strings with different UTC offsets will now create an Index of
585576

586577
.. ipython:: python
587578
588-
idx = pd.to_datetime(["2015-11-18 15:30:00+05:30", "2015-11-18 16:30:00+06:30"])
579+
idx = pd.to_datetime(["2015-11-18 15:30:00+05:30",
580+
"2015-11-18 16:30:00+06:30"])
589581
idx
590582
idx[0]
591583
idx[1]
@@ -595,7 +587,8 @@ that the dates have been converted to UTC
595587

596588
.. ipython:: python
597589
598-
pd.to_datetime(["2015-11-18 15:30:00+05:30", "2015-11-18 16:30:00+06:30"], utc=True)
590+
pd.to_datetime(["2015-11-18 15:30:00+05:30",
591+
"2015-11-18 16:30:00+06:30"], utc=True)
599592
600593
.. _whatsnew_0240.api_breaking.calendarday:
601594

@@ -867,7 +860,7 @@ Previous Behavior:
867860
In [4]: df = pd.DataFrame(arr)
868861
869862
In [5]: df == arr[[0], :]
870-
...: # comparison previously broadcast where arithmetic would raise
863+
...: # comparison previously broadcast where arithmetic would raise
871864
Out[5]:
872865
0 1
873866
0 True True
@@ -878,8 +871,8 @@ Previous Behavior:
878871
ValueError: Unable to coerce to DataFrame, shape must be (3, 2): given (1, 2)
879872
880873
In [7]: df == (1, 2)
881-
...: # length matches number of columns;
882-
...: # comparison previously raised where arithmetic would broadcast
874+
...: # length matches number of columns;
875+
...: # comparison previously raised where arithmetic would broadcast
883876
...
884877
ValueError: Invalid broadcasting comparison [(1, 2)] with block values
885878
In [8]: df + (1, 2)
@@ -890,8 +883,8 @@ Previous Behavior:
890883
2 5 7
891884
892885
In [9]: df == (1, 2, 3)
893-
...: # length matches number of rows
894-
...: # comparison previously broadcast where arithmetic would raise
886+
...: # length matches number of rows
887+
...: # comparison previously broadcast where arithmetic would raise
895888
Out[9]:
896889
0 1
897890
0 False True
@@ -1054,7 +1047,8 @@ Current Behavior:
10541047

10551048
.. code-block:: ipython
10561049
1057-
In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2], 'b': [3, 3, 4, 4, 4],
1050+
In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2],
1051+
...: 'b': [3, 3, 4, 4, 4],
10581052
...: 'c': [1, 1, np.nan, 1, 1]})
10591053
In [4]: pd.crosstab(df.a, df.b, normalize='columns')
10601054

0 commit comments

Comments
 (0)