Skip to content

Commit aa55c9a

Browse files
committed
Merge remote-tracking branch 'upstream/master' into windows_crlf
2 parents 13baede + db97089 commit aa55c9a

39 files changed

+647
-441
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build: clean_pyc
1313
python setup.py build_ext --inplace
1414

1515
lint-diff:
16-
git diff master --name-only -- "*.py" | grep "pandas" | xargs flake8
16+
git diff master --name-only -- "*.py" | grep -E "pandas|scripts" | xargs flake8
1717

1818
develop: build
1919
-python setup.py develop

ci/lint.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ if [ "$LINT" ]; then
2424
if [ $? -ne "0" ]; then
2525
RET=1
2626
fi
27+
28+
flake8 scripts/tests --filename=*.py
29+
if [ $? -ne "0" ]; then
30+
RET=1
31+
fi
2732
echo "Linting *.py DONE"
2833

2934
echo "Linting setup.py"
@@ -175,7 +180,7 @@ if [ "$LINT" ]; then
175180
RET=1
176181
fi
177182
echo "Check for old-style classes DONE"
178-
183+
179184
echo "Check for backticks incorrectly rendering because of missing spaces"
180185
grep -R --include="*.rst" -E "[a-zA-Z0-9]\`\`?[a-zA-Z0-9]" doc/source/
181186

ci/script_single.sh

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ elif [ "$COVERAGE" ]; then
2828
echo pytest -s -m "single" -r xXs --strict --cov=pandas --cov-report xml:/tmp/cov-single.xml --junitxml=/tmp/single.xml $TEST_ARGS pandas
2929
pytest -s -m "single" -r xXs --strict --cov=pandas --cov-report xml:/tmp/cov-single.xml --junitxml=/tmp/single.xml $TEST_ARGS pandas
3030

31+
echo pytest -s -r xXs --strict scripts
32+
pytest -s -r xXs --strict scripts
3133
else
3234
echo pytest -m "single" -r xXs --junitxml=/tmp/single.xml --strict $TEST_ARGS pandas
3335
pytest -m "single" -r xXs --junitxml=/tmp/single.xml --strict $TEST_ARGS pandas # TODO: doctest

doc/source/text.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ The same alignment can be used when ``others`` is a ``DataFrame``:
306306
Concatenating a Series and many objects into a Series
307307
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
308308

309-
All one-dimensional list-likes can be arbitrarily combined in a list-like container (including iterators, ``dict``-views, etc.):
309+
All one-dimensional list-likes can be combined in a list-like container (including iterators, ``dict``-views, etc.):
310310

311311
.. ipython:: python
312312

doc/source/timeseries.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,7 @@ To remove timezone from tz-aware ``DatetimeIndex``, use ``tz_localize(None)`` or
22282228
didx.tz_convert(None)
22292229
22302230
# tz_convert(None) is identical with tz_convert('UTC').tz_localize(None)
2231-
didx.tz_convert('UCT').tz_localize(None)
2231+
didx.tz_convert('UTC').tz_localize(None)
22322232
22332233
.. _timeseries.timezone_ambiguous:
22342234

doc/source/whatsnew/v0.24.0.txt

+9-4
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,15 @@ Other API Changes
508508
Deprecations
509509
~~~~~~~~~~~~
510510

511-
- :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`).
512-
- :meth:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`)
511+
- :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`)
512+
- :meth:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`)
513513
- :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`)
514514
- :meth:`Series.compress` is deprecated. Use ``Series[condition]`` instead (:issue:`18262`)
515515
- The signature of :meth:`Series.to_csv` has been uniformed to that of doc:meth:`DataFrame.to_csv`: the name of the first argument is now 'path_or_buf', the order of subsequent arguments has changed, the 'header' argument now defaults to True. (:issue:`19715`)
516516
- :meth:`Categorical.from_codes` has deprecated providing float values for the ``codes`` argument. (:issue:`21767`)
517517
- :func:`pandas.read_table` is deprecated. Instead, use :func:`pandas.read_csv` passing ``sep='\t'`` if necessary (:issue:`21948`)
518+
- :meth:`Series.str.cat` has deprecated using arbitrary list-likes *within* list-likes. A list-like container may still contain
519+
many ``Series``, ``Index`` or 1-dimensional ``np.ndarray``, or alternatively, only scalar values. (:issue:`21950`)
518520

519521
.. _whatsnew_0240.prior_deprecations:
520522

@@ -583,6 +585,7 @@ Datetimelike
583585
- Bug in :class:`DataFrame` comparisons against ``Timestamp``-like objects failing to raise ``TypeError`` for inequality checks with mismatched types (:issue:`8932`,:issue:`22163`)
584586
- Bug in :class:`DataFrame` with mixed dtypes including ``datetime64[ns]`` incorrectly raising ``TypeError`` on equality comparisons (:issue:`13128`,:issue:`22163`)
585587
- Bug in :meth:`DataFrame.eq` comparison against ``NaT`` incorrectly returning ``True`` or ``NaN`` (:issue:`15697`,:issue:`22163`)
588+
- Bug in :class:`DatetimeIndex` subtraction that incorrectly failed to raise `OverflowError` (:issue:`22492`, :issue:`22508`)
586589

587590
Timedelta
588591
^^^^^^^^^
@@ -664,6 +667,7 @@ Indexing
664667
- Fixed ``DataFrame[np.nan]`` when columns are non-unique (:issue:`21428`)
665668
- Bug when indexing :class:`DatetimeIndex` with nanosecond resolution dates and timezones (:issue:`11679`)
666669
- Bug where indexing with a Numpy array containing negative values would mutate the indexer (:issue:`21867`)
670+
- Bug where mixed indexes wouldn't allow integers for ``.at`` (:issue:`19860`)
667671
- ``Float64Index.get_loc`` now raises ``KeyError`` when boolean key passed. (:issue:`19087`)
668672

669673
Missing
@@ -737,9 +741,10 @@ Build Changes
737741
Other
738742
^^^^^
739743

740-
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`)
744+
- :meth:`~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`)
741745
- Require at least 0.28.2 version of ``cython`` to support read-only memoryviews (:issue:`21688`)
742-
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
746+
- :meth:`~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
747+
- :meth:`~pandas.io.formats.style.Styler.bar` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` and setting clipping range with ``vmin`` and ``vmax`` (:issue:`21548` and :issue:`21526`). ``NaN`` values are also handled properly.
743748
-
744749
-
745750
-

pandas/_libs/algos_common_helper.pxi.in

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ cpdef map_indices_{{name}}(ndarray[{{c_type}}] index):
5555

5656
Better to do this with Cython because of the enormous speed boost.
5757
"""
58-
cdef Py_ssize_t i, length
59-
cdef dict result = {}
58+
cdef:
59+
Py_ssize_t i, length
60+
dict result = {}
6061

6162
length = len(index)
6263

pandas/_libs/index.pyx

+1-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ cdef class IndexEngine:
104104
loc = self.get_loc(key)
105105
value = convert_scalar(arr, value)
106106

107-
if PySlice_Check(loc) or util.is_array(loc):
108-
arr[loc] = value
109-
else:
110-
util.set_value_at(arr, loc, value)
107+
arr[loc] = value
111108

112109
cpdef get_loc(self, object val):
113110
if is_definitely_invalid_key(val):

pandas/_libs/lib.pyx

+3-9
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,7 @@ def astype_intsafe(ndarray[object] arr, new_dtype):
492492
if is_datelike and checknull(v):
493493
result[i] = NPY_NAT
494494
else:
495-
# we can use the unsafe version because we know `result` is mutable
496-
# since it was created from `np.empty`
497-
util.set_value_at_unsafe(result, i, v)
495+
result[i] = v
498496

499497
return result
500498

@@ -505,9 +503,7 @@ cpdef ndarray[object] astype_unicode(ndarray arr):
505503
ndarray[object] result = np.empty(n, dtype=object)
506504

507505
for i in range(n):
508-
# we can use the unsafe version because we know `result` is mutable
509-
# since it was created from `np.empty`
510-
util.set_value_at_unsafe(result, i, unicode(arr[i]))
506+
result[i] = unicode(arr[i])
511507

512508
return result
513509

@@ -518,9 +514,7 @@ cpdef ndarray[object] astype_str(ndarray arr):
518514
ndarray[object] result = np.empty(n, dtype=object)
519515

520516
for i in range(n):
521-
# we can use the unsafe version because we know `result` is mutable
522-
# since it was created from `np.empty`
523-
util.set_value_at_unsafe(result, i, str(arr[i]))
517+
result[i] = str(arr[i])
524518

525519
return result
526520

pandas/_libs/parsers.pyx

+22-19
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cdef extern from "Python.h":
2929

3030
import numpy as np
3131
cimport numpy as cnp
32-
from numpy cimport ndarray, uint8_t, uint64_t, int64_t
32+
from numpy cimport ndarray, uint8_t, uint64_t, int64_t, float64_t
3333
cnp.import_array()
3434

3535
from util cimport UINT64_MAX, INT64_MAX, INT64_MIN
@@ -694,7 +694,7 @@ cdef class TextReader:
694694
if ptr == NULL:
695695
if not os.path.exists(source):
696696
raise compat.FileNotFoundError(
697-
'File %s does not exist' % source)
697+
'File {source} does not exist'.format(source=source))
698698
raise IOError('Initializing from file failed')
699699

700700
self.parser.source = ptr
@@ -772,9 +772,10 @@ cdef class TextReader:
772772

773773
if name == '':
774774
if self.has_mi_columns:
775-
name = 'Unnamed: %d_level_%d' % (i, level)
775+
name = ('Unnamed: {i}_level_{lvl}'
776+
.format(i=i, lvl=level))
776777
else:
777-
name = 'Unnamed: %d' % i
778+
name = 'Unnamed: {i}'.format(i=i)
778779
unnamed_count += 1
779780

780781
count = counts.get(name, 0)
@@ -849,8 +850,8 @@ cdef class TextReader:
849850
# 'data has %d fields'
850851
# % (passed_count, field_count))
851852

852-
if self.has_usecols and self.allow_leading_cols and \
853-
not callable(self.usecols):
853+
if (self.has_usecols and self.allow_leading_cols and
854+
not callable(self.usecols)):
854855
nuse = len(self.usecols)
855856
if nuse == passed_count:
856857
self.leading_cols = 0
@@ -1027,17 +1028,19 @@ cdef class TextReader:
10271028

10281029
if self.table_width - self.leading_cols > num_cols:
10291030
raise ParserError(
1030-
"Too many columns specified: expected %s and found %s" %
1031-
(self.table_width - self.leading_cols, num_cols))
1031+
"Too many columns specified: expected {expected} and "
1032+
"found {found}"
1033+
.format(expected=self.table_width - self.leading_cols,
1034+
found=num_cols))
10321035

10331036
results = {}
10341037
nused = 0
10351038
for i in range(self.table_width):
10361039
if i < self.leading_cols:
10371040
# Pass through leading columns always
10381041
name = i
1039-
elif self.usecols and not callable(self.usecols) and \
1040-
nused == len(self.usecols):
1042+
elif (self.usecols and not callable(self.usecols) and
1043+
nused == len(self.usecols)):
10411044
# Once we've gathered all requested columns, stop. GH5766
10421045
break
10431046
else:
@@ -1103,7 +1106,7 @@ cdef class TextReader:
11031106
col_res = _maybe_upcast(col_res)
11041107

11051108
if col_res is None:
1106-
raise ParserError('Unable to parse column %d' % i)
1109+
raise ParserError('Unable to parse column {i}'.format(i=i))
11071110

11081111
results[i] = col_res
11091112

@@ -1222,8 +1225,8 @@ cdef class TextReader:
12221225
elif dtype.kind == 'U':
12231226
width = dtype.itemsize
12241227
if width > 0:
1225-
raise TypeError("the dtype %s is not "
1226-
"supported for parsing" % dtype)
1228+
raise TypeError("the dtype {dtype} is not "
1229+
"supported for parsing".format(dtype=dtype))
12271230

12281231
# unicode variable width
12291232
return self._string_convert(i, start, end, na_filter,
@@ -1241,12 +1244,12 @@ cdef class TextReader:
12411244
return self._string_convert(i, start, end, na_filter,
12421245
na_hashset)
12431246
elif is_datetime64_dtype(dtype):
1244-
raise TypeError("the dtype %s is not supported "
1247+
raise TypeError("the dtype {dtype} is not supported "
12451248
"for parsing, pass this column "
1246-
"using parse_dates instead" % dtype)
1249+
"using parse_dates instead".format(dtype=dtype))
12471250
else:
1248-
raise TypeError("the dtype %s is not "
1249-
"supported for parsing" % dtype)
1251+
raise TypeError("the dtype {dtype} is not "
1252+
"supported for parsing".format(dtype=dtype))
12501253

12511254
cdef _string_convert(self, Py_ssize_t i, int64_t start, int64_t end,
12521255
bint na_filter, kh_str_t *na_hashset):
@@ -2058,7 +2061,7 @@ cdef kh_float64_t* kset_float64_from_list(values) except NULL:
20582061
khiter_t k
20592062
kh_float64_t *table
20602063
int ret = 0
2061-
cnp.float64_t val
2064+
float64_t val
20622065
object value
20632066

20642067
table = kh_init_float64()
@@ -2101,7 +2104,7 @@ cdef raise_parser_error(object base, parser_t *parser):
21012104
Py_XDECREF(type)
21022105
raise old_exc
21032106

2104-
message = '%s. C error: ' % base
2107+
message = '{base}. C error: '.format(base=base)
21052108
if parser.error_msg != NULL:
21062109
if PY3:
21072110
message += parser.error_msg.decode('utf-8')

pandas/_libs/reduction.pyx

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ cnp.import_array()
1818
cimport util
1919
from lib import maybe_convert_objects
2020

21-
is_numpy_prior_1_6_2 = LooseVersion(np.__version__) < '1.6.2'
22-
2321

2422
cdef _get_result_array(object obj, Py_ssize_t size, Py_ssize_t cnt):
2523

@@ -282,8 +280,7 @@ cdef class SeriesBinGrouper:
282280
result = _get_result_array(res,
283281
self.ngroups,
284282
len(self.dummy_arr))
285-
286-
util.assign_value_1d(result, i, res)
283+
result[i] = res
287284

288285
islider.advance(group_size)
289286
vslider.advance(group_size)
@@ -408,7 +405,7 @@ cdef class SeriesGrouper:
408405
self.ngroups,
409406
len(self.dummy_arr))
410407

411-
util.assign_value_1d(result, lab, res)
408+
result[lab] = res
412409
counts[lab] = group_size
413410
islider.advance(group_size)
414411
vslider.advance(group_size)

pandas/_libs/src/numpy_helper.h

-31
This file was deleted.

pandas/_libs/tslib.pyx

+3-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ from tslibs.nattype cimport checknull_with_nat, NPY_NAT
4646

4747
from tslibs.offsets cimport to_offset
4848

49-
from tslibs.timestamps cimport (create_timestamp_from_ts,
50-
_NS_UPPER_BOUND, _NS_LOWER_BOUND)
49+
from tslibs.timestamps cimport create_timestamp_from_ts
5150
from tslibs.timestamps import Timestamp
5251

5352

@@ -350,8 +349,8 @@ cpdef array_with_unit_to_datetime(ndarray values, unit, errors='coerce'):
350349
# check the bounds
351350
if not need_to_iterate:
352351

353-
if ((fvalues < _NS_LOWER_BOUND).any()
354-
or (fvalues > _NS_UPPER_BOUND).any()):
352+
if ((fvalues < Timestamp.min.value).any()
353+
or (fvalues > Timestamp.max.value).any()):
355354
raise OutOfBoundsDatetime("cannot convert input with unit "
356355
"'{unit}'".format(unit=unit))
357356
result = (iresult * m).astype('M8[ns]')

pandas/_libs/tslibs/timestamps.pxd

-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ from np_datetime cimport npy_datetimestruct
66
cdef object create_timestamp_from_ts(int64_t value,
77
npy_datetimestruct dts,
88
object tz, object freq)
9-
10-
cdef int64_t _NS_UPPER_BOUND, _NS_LOWER_BOUND

0 commit comments

Comments
 (0)