Skip to content

Commit 5a7adc6

Browse files
Merge branch 'master' of git://github.com/pandas-dev/pandas into ValueErrorInPy3
2 parents f9ab133 + 5e224fb commit 5a7adc6

File tree

14 files changed

+201
-72
lines changed

14 files changed

+201
-72
lines changed

doc/source/whatsnew/v0.24.1.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ Fixed Regressions
2222

2323
- Bug in :meth:`DataFrame.itertuples` with ``records`` orient raising an ``AttributeError`` when the ``DataFrame`` contained more than 255 columns (:issue:`24939`)
2424
- Bug in :meth:`DataFrame.itertuples` orient converting integer column names to strings prepended with an underscore (:issue:`24940`)
25+
- Fixed regression in :func:`read_sql` when passing certain queries with MySQL/pymysql (:issue:`24988`).
2526
- Fixed regression in :class:`Index.intersection` incorrectly sorting the values by default (:issue:`24959`).
2627
- Fixed regression in :func:`merge` when merging an empty ``DataFrame`` with multiple timezone-aware columns on one of the timezone-aware columns (:issue:`25014`).
28+
- Fixed regression in :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` where passing ``None`` failed to remove the axis name (:issue:`25034`)
2729

2830
.. _whatsnew_0241.enhancements:
2931

doc/source/whatsnew/v0.24.2.rst

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
:orphan:
2+
3+
.. _whatsnew_0242:
4+
5+
Whats New in 0.24.2 (February XX, 2019)
6+
---------------------------------------
7+
8+
.. warning::
9+
10+
The 0.24.x series of releases will be the last to support Python 2. Future feature
11+
releases will support Python 3 only. See :ref:`install.dropping-27` for more.
12+
13+
{{ header }}
14+
15+
These are the changes in pandas 0.24.2. See :ref:`release` for a full changelog
16+
including other versions of pandas.
17+
18+
.. _whatsnew_0242.regressions:
19+
20+
Fixed Regressions
21+
^^^^^^^^^^^^^^^^^
22+
23+
-
24+
-
25+
-
26+
27+
.. _whatsnew_0242.enhancements:
28+
29+
Enhancements
30+
^^^^^^^^^^^^
31+
32+
-
33+
-
34+
35+
.. _whatsnew_0242.bug_fixes:
36+
37+
Bug Fixes
38+
~~~~~~~~~
39+
40+
**Conversion**
41+
42+
-
43+
-
44+
-
45+
46+
**Indexing**
47+
48+
-
49+
-
50+
-
51+
52+
**I/O**
53+
54+
-
55+
-
56+
-
57+
58+
**Categorical**
59+
60+
-
61+
-
62+
-
63+
64+
**Timezones**
65+
66+
-
67+
-
68+
-
69+
70+
**Timedelta**
71+
72+
-
73+
-
74+
-
75+
76+
**Reshaping**
77+
78+
-
79+
-
80+
-
81+
82+
**Visualization**
83+
84+
-
85+
-
86+
-
87+
88+
**Other**
89+
90+
-
91+
-
92+
-
93+
94+
.. _whatsnew_0.242.contributors:
95+
96+
Contributors
97+
~~~~~~~~~~~~
98+
99+
.. contributors:: v0.24.1..v0.24.2

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ including other versions of pandas.
1919
Other Enhancements
2020
^^^^^^^^^^^^^^^^^^
2121

22-
-
22+
- :meth:`Timestamp.replace` now supports the ``fold`` argument to disambiguate DST transition times (:issue:`25017`)
2323
-
2424
-
2525

pandas/_libs/tslibs/nattype.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ class NaTType(_NaT):
669669
nanosecond : int, optional
670670
tzinfo : tz-convertible, optional
671671
fold : int, optional, default is 0
672-
added in 3.6, NotImplemented
673672
674673
Returns
675674
-------

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import sys
23
import warnings
34

45
from cpython cimport (PyObject_RichCompareBool, PyObject_RichCompare,
@@ -43,10 +44,11 @@ from pandas._libs.tslibs.timezones import UTC
4344
# Constants
4445
_zero_time = datetime_time(0, 0)
4546
_no_input = object()
46-
47+
PY36 = sys.version_info >= (3, 6)
4748

4849
# ----------------------------------------------------------------------
4950

51+
5052
def maybe_integer_op_deprecated(obj):
5153
# GH#22535 add/sub of integers and int-arrays is deprecated
5254
if obj.freq is not None:
@@ -1195,7 +1197,6 @@ class Timestamp(_Timestamp):
11951197
nanosecond : int, optional
11961198
tzinfo : tz-convertible, optional
11971199
fold : int, optional, default is 0
1198-
added in 3.6, NotImplemented
11991200
12001201
Returns
12011202
-------
@@ -1252,12 +1253,16 @@ class Timestamp(_Timestamp):
12521253
# see GH#18319
12531254
ts_input = _tzinfo.localize(datetime(dts.year, dts.month, dts.day,
12541255
dts.hour, dts.min, dts.sec,
1255-
dts.us))
1256+
dts.us),
1257+
is_dst=not bool(fold))
12561258
_tzinfo = ts_input.tzinfo
12571259
else:
1258-
ts_input = datetime(dts.year, dts.month, dts.day,
1259-
dts.hour, dts.min, dts.sec, dts.us,
1260-
tzinfo=_tzinfo)
1260+
kwargs = {'year': dts.year, 'month': dts.month, 'day': dts.day,
1261+
'hour': dts.hour, 'minute': dts.min, 'second': dts.sec,
1262+
'microsecond': dts.us, 'tzinfo': _tzinfo}
1263+
if PY36:
1264+
kwargs['fold'] = fold
1265+
ts_input = datetime(**kwargs)
12611266

12621267
ts = convert_datetime_to_tsobject(ts_input, _tzinfo)
12631268
value = ts.value + (dts.ps // 1000)

pandas/compat/pickle_compat.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def load_newobj_ex(self):
201201
pass
202202

203203

204-
def load(fh, encoding=None, compat=False, is_verbose=False):
204+
def load(fh, encoding=None, is_verbose=False):
205205
"""load a pickle, with a provided encoding
206206
207207
if compat is True:
@@ -212,7 +212,6 @@ def load(fh, encoding=None, compat=False, is_verbose=False):
212212
----------
213213
fh : a filelike object
214214
encoding : an optional encoding
215-
compat : provide Series compatibility mode, boolean, default False
216215
is_verbose : show exception output
217216
"""
218217

pandas/core/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
12341234
If True then the object returned will contain the relative
12351235
frequencies of the unique values.
12361236
sort : boolean, default True
1237-
Sort by values.
1237+
Sort by frequencies.
12381238
ascending : boolean, default False
12391239
Sort in ascending order.
12401240
bins : integer, optional

pandas/core/frame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4625,7 +4625,8 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
46254625
def drop_duplicates(self, subset=None, keep='first', inplace=False):
46264626
"""
46274627
Return DataFrame with duplicate rows removed, optionally only
4628-
considering certain columns.
4628+
considering certain columns. Indexes, including time indexes
4629+
are ignored.
46294630
46304631
Parameters
46314632
----------

pandas/core/generic.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
by : str or list of str
6262
Name or list of names to sort by""")
6363

64+
# sentinel value to use as kwarg in place of None when None has special meaning
65+
# and needs to be distinguished from a user explicitly passing None.
66+
sentinel = object()
67+
6468

6569
def _single_replace(self, to_replace, method, inplace, limit):
6670
"""
@@ -290,11 +294,16 @@ def _construct_axes_dict_for_slice(self, axes=None, **kwargs):
290294
d.update(kwargs)
291295
return d
292296

293-
def _construct_axes_from_arguments(self, args, kwargs, require_all=False):
297+
def _construct_axes_from_arguments(
298+
self, args, kwargs, require_all=False, sentinel=None):
294299
"""Construct and returns axes if supplied in args/kwargs.
295300
296301
If require_all, raise if all axis arguments are not supplied
297302
return a tuple of (axes, kwargs).
303+
304+
sentinel specifies the default parameter when an axis is not
305+
supplied; useful to distinguish when a user explicitly passes None
306+
in scenarios where None has special meaning.
298307
"""
299308

300309
# construct the args
@@ -322,7 +331,7 @@ def _construct_axes_from_arguments(self, args, kwargs, require_all=False):
322331
raise TypeError("not enough/duplicate arguments "
323332
"specified!")
324333

325-
axes = {a: kwargs.pop(a, None) for a in self._AXIS_ORDERS}
334+
axes = {a: kwargs.pop(a, sentinel) for a in self._AXIS_ORDERS}
326335
return axes, kwargs
327336

328337
@classmethod
@@ -1089,7 +1098,7 @@ def rename(self, *args, **kwargs):
10891098

10901099
@rewrite_axis_style_signature('mapper', [('copy', True),
10911100
('inplace', False)])
1092-
def rename_axis(self, mapper=None, **kwargs):
1101+
def rename_axis(self, mapper=sentinel, **kwargs):
10931102
"""
10941103
Set the name of the axis for the index or columns.
10951104
@@ -1218,7 +1227,8 @@ class name
12181227
cat 4 0
12191228
monkey 2 2
12201229
"""
1221-
axes, kwargs = self._construct_axes_from_arguments((), kwargs)
1230+
axes, kwargs = self._construct_axes_from_arguments(
1231+
(), kwargs, sentinel=sentinel)
12221232
copy = kwargs.pop('copy', True)
12231233
inplace = kwargs.pop('inplace', False)
12241234
axis = kwargs.pop('axis', 0)
@@ -1231,7 +1241,7 @@ class name
12311241

12321242
inplace = validate_bool_kwarg(inplace, 'inplace')
12331243

1234-
if (mapper is not None):
1244+
if (mapper is not sentinel):
12351245
# Use v0.23 behavior if a scalar or list
12361246
non_mapper = is_scalar(mapper) or (is_list_like(mapper) and not
12371247
is_dict_like(mapper))
@@ -1254,7 +1264,7 @@ class name
12541264

12551265
for axis in lrange(self._AXIS_LEN):
12561266
v = axes.get(self._AXIS_NAMES[axis])
1257-
if v is None:
1267+
if v is sentinel:
12581268
continue
12591269
non_mapper = is_scalar(v) or (is_list_like(v) and not
12601270
is_dict_like(v))

pandas/io/pickle.py

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
""" pickle compat """
22
import warnings
33

4-
import numpy as np
5-
from numpy.lib.format import read_array, write_array
4+
from numpy.lib.format import read_array
65

76
from pandas.compat import PY3, BytesIO, cPickle as pkl, pickle_compat as pc
87

@@ -76,6 +75,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL):
7675
try:
7776
f.write(pkl.dumps(obj, protocol=protocol))
7877
finally:
78+
f.close()
7979
for _f in fh:
8080
_f.close()
8181

@@ -138,63 +138,32 @@ def read_pickle(path, compression='infer'):
138138
>>> os.remove("./dummy.pkl")
139139
"""
140140
path = _stringify_path(path)
141+
f, fh = _get_handle(path, 'rb', compression=compression, is_text=False)
142+
143+
# 1) try with cPickle
144+
# 2) try with the compat pickle to handle subclass changes
145+
# 3) pass encoding only if its not None as py2 doesn't handle the param
141146

142-
def read_wrapper(func):
143-
# wrapper file handle open/close operation
144-
f, fh = _get_handle(path, 'rb',
145-
compression=compression,
146-
is_text=False)
147-
try:
148-
return func(f)
149-
finally:
150-
for _f in fh:
151-
_f.close()
152-
153-
def try_read(path, encoding=None):
154-
# try with cPickle
155-
# try with current pickle, if we have a Type Error then
156-
# try with the compat pickle to handle subclass changes
157-
# pass encoding only if its not None as py2 doesn't handle
158-
# the param
159-
160-
# cpickle
161-
# GH 6899
162-
try:
163-
with warnings.catch_warnings(record=True):
164-
# We want to silence any warnings about, e.g. moved modules.
165-
warnings.simplefilter("ignore", Warning)
166-
return read_wrapper(lambda f: pkl.load(f))
167-
except Exception: # noqa: E722
168-
# reg/patched pickle
169-
# compat not used in pandas/compat/pickle_compat.py::load
170-
# TODO: remove except block OR modify pc.load to use compat
171-
try:
172-
return read_wrapper(
173-
lambda f: pc.load(f, encoding=encoding, compat=False))
174-
# compat pickle
175-
except Exception: # noqa: E722
176-
return read_wrapper(
177-
lambda f: pc.load(f, encoding=encoding, compat=True))
178147
try:
179-
return try_read(path)
148+
with warnings.catch_warnings(record=True):
149+
# We want to silence any warnings about, e.g. moved modules.
150+
warnings.simplefilter("ignore", Warning)
151+
return pkl.load(f)
180152
except Exception: # noqa: E722
181-
if PY3:
182-
return try_read(path, encoding='latin1')
183-
raise
184-
153+
try:
154+
return pc.load(f, encoding=None)
155+
except Exception: # noqa: E722
156+
if PY3:
157+
return pc.load(f, encoding='latin1')
158+
raise
159+
finally:
160+
f.close()
161+
for _f in fh:
162+
_f.close()
185163

186164
# compat with sparse pickle / unpickle
187165

188166

189-
def _pickle_array(arr):
190-
arr = arr.view(np.ndarray)
191-
192-
buf = BytesIO()
193-
write_array(buf, arr)
194-
195-
return buf.getvalue()
196-
197-
198167
def _unpickle_array(bytes):
199168
arr = read_array(BytesIO(bytes))
200169

pandas/io/sql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ def read_sql(sql, con, index_col=None, coerce_float=True, params=None,
381381

382382
try:
383383
_is_table_name = pandas_sql.has_table(sql)
384-
except (ImportError, AttributeError):
384+
except Exception:
385+
# using generic exception to catch errors from sql drivers (GH24988)
385386
_is_table_name = False
386387

387388
if _is_table_name:

0 commit comments

Comments
 (0)