Skip to content

Commit 3591894

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas
2 parents 5e0fbe3 + a76df79 commit 3591894

File tree

10 files changed

+160
-112
lines changed

10 files changed

+160
-112
lines changed

ci/run_tests.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ do
5050
# if no tests are found (the case of "single and slow"), pytest exits with code 5, and would make the script fail, if not for the below code
5151
sh -c "$PYTEST_CMD; ret=\$?; [ \$ret = 5 ] && exit 0 || exit \$ret"
5252

53-
if [[ "$COVERAGE" && $? == 0 ]]; then
54-
echo "uploading coverage for $TYPE tests"
55-
echo "bash <(curl -s https://codecov.io/bash) -Z -c -F $TYPE -f $COVERAGE_FNAME"
56-
bash <(curl -s https://codecov.io/bash) -Z -c -F $TYPE -f $COVERAGE_FNAME
57-
fi
53+
# 2019-08-21 disabling because this is hitting HTTP 400 errors GH#27602
54+
# if [[ "$COVERAGE" && $? == 0 && "$TRAVIS_BRANCH" == "master" ]]; then
55+
# echo "uploading coverage for $TYPE tests"
56+
# echo "bash <(curl -s https://codecov.io/bash) -Z -c -F $TYPE -f $COVERAGE_FNAME"
57+
# bash <(curl -s https://codecov.io/bash) -Z -c -F $TYPE -f $COVERAGE_FNAME
58+
# fi
5859
done

doc/source/whatsnew/v0.25.1.rst

Lines changed: 23 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,44 @@
11
.. _whatsnew_0251:
22

3-
What's new in 0.25.1 (July XX, 2019)
4-
------------------------------------
3+
What's new in 0.25.1 (August 21, 2019)
4+
--------------------------------------
55

6-
Enhancements
7-
~~~~~~~~~~~~
8-
9-
10-
.. _whatsnew_0251.enhancements.other:
6+
These are the changes in pandas 0.25.1. See :ref:`release` for a full changelog
7+
including other versions of pandas.
118

12-
Other enhancements
13-
^^^^^^^^^^^^^^^^^^
9+
I/O and LZMA
10+
~~~~~~~~~~~~
1411

15-
-
16-
-
17-
-
12+
Some users may unknowingly have an incomplete Python installation lacking the `lzma` module from the standard library. In this case, `import pandas` failed due to an `ImportError` (:issue: `27575`).
13+
Pandas will now warn, rather than raising an `ImportError` if the `lzma` module is not present. Any subsequent attempt to use `lzma` methods will raise a `RuntimeError`.
14+
A possible fix for the lack of the `lzma` module is to ensure you have the necessary libraries and then re-install Python.
15+
For example, on MacOS installing Python with `pyenv` may lead to an incomplete Python installation due to unmet system dependencies at compilation time (like `xz`). Compilation will succeed, but Python might fail at run time. The issue can be solved by installing the necessary dependencies and then re-installing Python.
1816

1917
.. _whatsnew_0251.bug_fixes:
2018

2119
Bug fixes
2220
~~~~~~~~~
2321

24-
2522
Categorical
2623
^^^^^^^^^^^
2724

28-
- Bug in :meth:`Categorical.fillna` would replace all values, not just those that are ``NaN`` (:issue:`26215`)
29-
-
25+
- Bug in :meth:`Categorical.fillna` that would replace all values, not just those that are ``NaN`` (:issue:`26215`)
3026

3127
Datetimelike
3228
^^^^^^^^^^^^
29+
3330
- Bug in :func:`to_datetime` where passing a timezone-naive :class:`DatetimeArray` or :class:`DatetimeIndex` and ``utc=True`` would incorrectly return a timezone-naive result (:issue:`27733`)
3431
- Bug in :meth:`Period.to_timestamp` where a :class:`Period` outside the :class:`Timestamp` implementation bounds (roughly 1677-09-21 to 2262-04-11) would return an incorrect :class:`Timestamp` instead of raising ``OutOfBoundsDatetime`` (:issue:`19643`)
35-
-
36-
-
37-
38-
Timedelta
39-
^^^^^^^^^
40-
41-
-
42-
-
43-
-
32+
- Bug in iterating over :class:`DatetimeIndex` when the underlying data is read-only (:issue:`28055`)
4433

4534
Timezones
4635
^^^^^^^^^
4736

4837
- Bug in :class:`Index` where a numpy object array with a timezone aware :class:`Timestamp` and ``np.nan`` would not return a :class:`DatetimeIndex` (:issue:`27011`)
49-
-
50-
-
5138

5239
Numeric
5340
^^^^^^^
41+
5442
- Bug in :meth:`Series.interpolate` when using a timezone aware :class:`DatetimeIndex` (:issue:`27548`)
5543
- Bug when printing negative floating point complex numbers would raise an ``IndexError`` (:issue:`27484`)
5644
- Bug where :class:`DataFrame` arithmetic operators such as :meth:`DataFrame.mul` with a :class:`Series` with axis=1 would raise an ``AttributeError`` on :class:`DataFrame` larger than the minimum threshold to invoke numexpr (:issue:`27636`)
@@ -60,23 +48,11 @@ Conversion
6048
^^^^^^^^^^
6149

6250
- Improved the warnings for the deprecated methods :meth:`Series.real` and :meth:`Series.imag` (:issue:`27610`)
63-
-
64-
-
65-
66-
Strings
67-
^^^^^^^
68-
69-
-
70-
-
71-
-
72-
7351

7452
Interval
7553
^^^^^^^^
54+
7655
- Bug in :class:`IntervalIndex` where `dir(obj)` would raise ``ValueError`` (:issue:`27571`)
77-
-
78-
-
79-
-
8056

8157
Indexing
8258
^^^^^^^^
@@ -85,47 +61,35 @@ Indexing
8561
- Break reference cycle involving :class:`Index` and other index classes to allow garbage collection of index objects without running the GC. (:issue:`27585`, :issue:`27840`)
8662
- Fix regression in assigning values to a single column of a DataFrame with a ``MultiIndex`` columns (:issue:`27841`).
8763
- Fix regression in ``.ix`` fallback with an ``IntervalIndex`` (:issue:`27865`).
88-
-
8964

9065
Missing
9166
^^^^^^^
9267

93-
- Bug in :func:`pandas.isnull` or :func:`pandas.isna` when the input is a type e.g. `type(pandas.Series())` (:issue:`27482`)
94-
-
95-
-
96-
97-
MultiIndex
98-
^^^^^^^^^^
99-
100-
-
101-
-
102-
-
68+
- Bug in :func:`pandas.isnull` or :func:`pandas.isna` when the input is a type e.g. ``type(pandas.Series())`` (:issue:`27482`)
10369

10470
I/O
10571
^^^
72+
10673
- Avoid calling ``S3File.s3`` when reading parquet, as this was removed in s3fs version 0.3.0 (:issue:`27756`)
10774
- Better error message when a negative header is passed in :func:`pandas.read_csv` (:issue:`27779`)
108-
- Follow the ``min_rows`` display option (introduced in v0.25.0) correctly in the html repr in the notebook (:issue:`27991`).
109-
-
75+
- Follow the ``min_rows`` display option (introduced in v0.25.0) correctly in the HTML repr in the notebook (:issue:`27991`).
11076

11177
Plotting
11278
^^^^^^^^
11379

114-
- Added a pandas_plotting_backends entrypoint group for registering plot backends. See :ref:`extending.plotting-backends` for more (:issue:`26747`).
80+
- Added a ``pandas_plotting_backends`` entrypoint group for registering plot backends. See :ref:`extending.plotting-backends` for more (:issue:`26747`).
11581
- Fixed the re-instatement of Matplotlib datetime converters after calling
116-
`pandas.plotting.deregister_matplotlib_converters()` (:issue:`27481`).
117-
-
82+
:meth:`pandas.plotting.deregister_matplotlib_converters` (:issue:`27481`).
11883
- Fix compatibility issue with matplotlib when passing a pandas ``Index`` to a plot call (:issue:`27775`).
119-
-
12084

12185
Groupby/resample/rolling
12286
^^^^^^^^^^^^^^^^^^^^^^^^
12387

88+
- Fixed regression in :meth:`pands.core.groupby.DataFrameGroupBy.quantile` raising when multiple quantiles are given (:issue:`27526`)
12489
- Bug in :meth:`pandas.core.groupby.DataFrameGroupBy.transform` where applying a timezone conversion lambda function would drop timezone information (:issue:`27496`)
12590
- Bug in :meth:`pandas.core.groupby.GroupBy.nth` where ``observed=False`` was being ignored for Categorical groupers (:issue:`26385`)
12691
- Bug in windowing over read-only arrays (:issue:`27766`)
12792
- Fixed segfault in `pandas.core.groupby.DataFrameGroupBy.quantile` when an invalid quantile was passed (:issue:`27470`)
128-
-
12993

13094
Reshaping
13195
^^^^^^^^^
@@ -137,40 +101,13 @@ Reshaping
137101

138102
Sparse
139103
^^^^^^
140-
- Bug in reductions for :class:`Series` with Sparse dtypes (:issue:`27080`)
141-
-
142-
-
143-
-
144-
145-
146-
Build Changes
147-
^^^^^^^^^^^^^
148-
149-
-
150-
-
151-
-
152-
153-
ExtensionArray
154-
^^^^^^^^^^^^^^
155104

156-
-
157-
-
158-
-
105+
- Bug in reductions for :class:`Series` with Sparse dtypes (:issue:`27080`)
159106

160107
Other
161108
^^^^^
162-
- Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when replacing timezone-aware timestamps using a dict-like replacer (:issue:`27720`)
163-
-
164-
-
165-
-
166-
167-
I/O and LZMA
168-
~~~~~~~~~~~~
169109

170-
Some users may unknowingly have an incomplete Python installation, which lacks the `lzma` module from the standard library. In this case, `import pandas` failed due to an `ImportError` (:issue: `27575`).
171-
Pandas will now warn, rather than raising an `ImportError` if the `lzma` module is not present. Any subsequent attempt to use `lzma` methods will raise a `RuntimeError`.
172-
A possible fix for the lack of the `lzma` module is to ensure you have the necessary libraries and then re-install Python.
173-
For example, on MacOS installing Python with `pyenv` may lead to an incomplete Python installation due to unmet system dependencies at compilation time (like `xz`). Compilation will succeed, but Python might fail at run time. The issue can be solved by installing the necessary dependencies and then re-installing Python.
110+
- Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when replacing timezone-aware timestamps using a dict-like replacer (:issue:`27720`)
174111

175112
.. _whatsnew_0.251.contributors:
176113

pandas/_libs/tslib.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ cdef inline object create_time_from_ts(
7171

7272
@cython.wraparound(False)
7373
@cython.boundscheck(False)
74-
def ints_to_pydatetime(int64_t[:] arr, object tz=None, object freq=None,
74+
def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
7575
str box="datetime"):
7676
"""
7777
Convert an i8 repr to an ndarray of datetimes, date, time or Timestamp

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,7 @@ def _ensure_valid_index(self, value):
30983098
passed value.
30993099
"""
31003100
# GH5632, make sure that we are a Series convertible
3101-
if not len(self.index) and is_list_like(value):
3101+
if not len(self.index) and is_list_like(value) and len(value):
31023102
try:
31033103
value = Series(value)
31043104
except (ValueError, NotImplementedError, TypeError):

pandas/core/groupby/groupby.py

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,7 @@ def quantile(self, q=0.5, interpolation="linear"):
18741874
a 2.0
18751875
b 3.0
18761876
"""
1877+
from pandas import concat
18771878

18781879
def pre_processor(vals: np.ndarray) -> Tuple[np.ndarray, Optional[Type]]:
18791880
if is_object_dtype(vals):
@@ -1901,18 +1902,57 @@ def post_processor(vals: np.ndarray, inference: Optional[Type]) -> np.ndarray:
19011902

19021903
return vals
19031904

1904-
return self._get_cythonized_result(
1905-
"group_quantile",
1906-
self.grouper,
1907-
aggregate=True,
1908-
needs_values=True,
1909-
needs_mask=True,
1910-
cython_dtype=np.float64,
1911-
pre_processing=pre_processor,
1912-
post_processing=post_processor,
1913-
q=q,
1914-
interpolation=interpolation,
1915-
)
1905+
if is_scalar(q):
1906+
return self._get_cythonized_result(
1907+
"group_quantile",
1908+
self.grouper,
1909+
aggregate=True,
1910+
needs_values=True,
1911+
needs_mask=True,
1912+
cython_dtype=np.float64,
1913+
pre_processing=pre_processor,
1914+
post_processing=post_processor,
1915+
q=q,
1916+
interpolation=interpolation,
1917+
)
1918+
else:
1919+
results = [
1920+
self._get_cythonized_result(
1921+
"group_quantile",
1922+
self.grouper,
1923+
aggregate=True,
1924+
needs_values=True,
1925+
needs_mask=True,
1926+
cython_dtype=np.float64,
1927+
pre_processing=pre_processor,
1928+
post_processing=post_processor,
1929+
q=qi,
1930+
interpolation=interpolation,
1931+
)
1932+
for qi in q
1933+
]
1934+
result = concat(results, axis=0, keys=q)
1935+
# fix levels to place quantiles on the inside
1936+
# TODO(GH-10710): Ideally, we could write this as
1937+
# >>> result.stack(0).loc[pd.IndexSlice[:, ..., q], :]
1938+
# but this hits https://github.com/pandas-dev/pandas/issues/10710
1939+
# which doesn't reorder the list-like `q` on the inner level.
1940+
order = np.roll(list(range(result.index.nlevels)), -1)
1941+
result = result.reorder_levels(order)
1942+
result = result.reindex(q, level=-1)
1943+
1944+
# fix order.
1945+
hi = len(q) * self.ngroups
1946+
arr = np.arange(0, hi, self.ngroups)
1947+
arrays = []
1948+
1949+
for i in range(self.ngroups):
1950+
arr = arr + i
1951+
arrays.append(arr)
1952+
1953+
indices = np.concatenate(arrays)
1954+
assert len(indices) == len(result)
1955+
return result.take(indices)
19161956

19171957
@Substitution(name="groupby")
19181958
def ngroup(self, ascending=True):

pandas/tests/frame/test_indexing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,14 @@ def test_setitem_empty_frame_with_boolean(self, dtype, kwargs):
821821
df[df > df2] = 47
822822
assert_frame_equal(df, df2)
823823

824+
def test_setitem_with_empty_listlike(self):
825+
# GH #17101
826+
index = pd.Index([], name="idx")
827+
result = pd.DataFrame(columns=["A"], index=index)
828+
result["A"] = []
829+
expected = pd.DataFrame(columns=["A"], index=index)
830+
tm.assert_index_equal(result.index, expected.index)
831+
824832
def test_setitem_scalars_no_index(self):
825833
# GH16823 / 17894
826834
df = DataFrame()

pandas/tests/groupby/test_function.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,57 @@ def test_quantile(interpolation, a_vals, b_vals, q):
12381238
tm.assert_frame_equal(result, expected)
12391239

12401240

1241+
def test_quantile_array():
1242+
# https://github.com/pandas-dev/pandas/issues/27526
1243+
df = pd.DataFrame({"A": [0, 1, 2, 3, 4]})
1244+
result = df.groupby([0, 0, 1, 1, 1]).quantile([0.25])
1245+
1246+
index = pd.MultiIndex.from_product([[0, 1], [0.25]])
1247+
expected = pd.DataFrame({"A": [0.25, 2.50]}, index=index)
1248+
tm.assert_frame_equal(result, expected)
1249+
1250+
df = pd.DataFrame({"A": [0, 1, 2, 3], "B": [4, 5, 6, 7]})
1251+
index = pd.MultiIndex.from_product([[0, 1], [0.25, 0.75]])
1252+
1253+
result = df.groupby([0, 0, 1, 1]).quantile([0.25, 0.75])
1254+
expected = pd.DataFrame(
1255+
{"A": [0.25, 0.75, 2.25, 2.75], "B": [4.25, 4.75, 6.25, 6.75]}, index=index
1256+
)
1257+
tm.assert_frame_equal(result, expected)
1258+
1259+
1260+
def test_quantile_array_no_sort():
1261+
df = pd.DataFrame({"A": [0, 1, 2], "B": [3, 4, 5]})
1262+
result = df.groupby([1, 0, 1], sort=False).quantile([0.25, 0.5, 0.75])
1263+
expected = pd.DataFrame(
1264+
{"A": [0.5, 1.0, 1.5, 1.0, 1.0, 1.0], "B": [3.5, 4.0, 4.5, 4.0, 4.0, 4.0]},
1265+
index=pd.MultiIndex.from_product([[1, 0], [0.25, 0.5, 0.75]]),
1266+
)
1267+
tm.assert_frame_equal(result, expected)
1268+
1269+
result = df.groupby([1, 0, 1], sort=False).quantile([0.75, 0.25])
1270+
expected = pd.DataFrame(
1271+
{"A": [1.5, 0.5, 1.0, 1.0], "B": [4.5, 3.5, 4.0, 4.0]},
1272+
index=pd.MultiIndex.from_product([[1, 0], [0.75, 0.25]]),
1273+
)
1274+
tm.assert_frame_equal(result, expected)
1275+
1276+
1277+
def test_quantile_array_multiple_levels():
1278+
df = pd.DataFrame(
1279+
{"A": [0, 1, 2], "B": [3, 4, 5], "c": ["a", "a", "a"], "d": ["a", "a", "b"]}
1280+
)
1281+
result = df.groupby(["c", "d"]).quantile([0.25, 0.75])
1282+
index = pd.MultiIndex.from_tuples(
1283+
[("a", "a", 0.25), ("a", "a", 0.75), ("a", "b", 0.25), ("a", "b", 0.75)],
1284+
names=["c", "d", None],
1285+
)
1286+
expected = pd.DataFrame(
1287+
{"A": [0.25, 0.75, 2.0, 2.0], "B": [3.25, 3.75, 5.0, 5.0]}, index=index
1288+
)
1289+
tm.assert_frame_equal(result, expected)
1290+
1291+
12411292
def test_quantile_raises():
12421293
df = pd.DataFrame(
12431294
[["foo", "a"], ["foo", "b"], ["foo", "c"]], columns=["key", "val"]

pandas/tests/indexes/datetimes/test_misc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,11 @@ def test_nanosecond_field(self):
377377
dti = DatetimeIndex(np.arange(10))
378378

379379
tm.assert_index_equal(dti.nanosecond, pd.Index(np.arange(10, dtype=np.int64)))
380+
381+
382+
def test_iter_readonly():
383+
# GH#28055 ints_to_pydatetime with readonly array
384+
arr = np.array([np.datetime64("2012-02-15T12:00:00.000000000")])
385+
arr.setflags(write=False)
386+
dti = pd.to_datetime(arr)
387+
list(dti)

0 commit comments

Comments
 (0)