Skip to content

Commit 1395b65

Browse files
committed
Merge remote-tracking branch 'upstream/master' into styler_apply
# Conflicts: # doc/source/whatsnew/v1.3.0.rst
2 parents f1571a8 + 7b795b2 commit 1395b65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+998
-579
lines changed

asv_bench/benchmarks/series_methods.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,29 @@ def time_clip(self, n):
284284

285285
class ValueCounts:
286286

287-
params = ["int", "uint", "float", "object"]
288-
param_names = ["dtype"]
287+
params = [[10 ** 3, 10 ** 4, 10 ** 5], ["int", "uint", "float", "object"]]
288+
param_names = ["N", "dtype"]
289289

290-
def setup(self, dtype):
291-
self.s = Series(np.random.randint(0, 1000, size=100000)).astype(dtype)
290+
def setup(self, N, dtype):
291+
self.s = Series(np.random.randint(0, N, size=10 * N)).astype(dtype)
292292

293-
def time_value_counts(self, dtype):
293+
def time_value_counts(self, N, dtype):
294294
self.s.value_counts()
295295

296296

297+
class Mode:
298+
299+
params = [[10 ** 3, 10 ** 4, 10 ** 5], ["int", "uint", "float", "object"]]
300+
param_names = ["N", "dtype"]
301+
302+
def setup(self, N, dtype):
303+
np.random.seed(42)
304+
self.s = Series(np.random.randint(0, N, size=10 * N)).astype(dtype)
305+
306+
def time_mode(self, N, dtype):
307+
self.s.mode()
308+
309+
297310
class Dir:
298311
def setup(self):
299312
self.s = Series(index=tm.makeStringIndex(10000))

ci/code_checks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
6464
# this particular codebase (e.g. src/headers, src/klib). However,
6565
# we can lint all header files since they aren't "generated" like C files are.
6666
MSG='Linting .c and .h' ; echo $MSG
67-
cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp
67+
cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/src/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp
6868
RET=$(($RET + $?)) ; echo $MSG "DONE"
6969

7070
fi

doc/source/user_guide/visualization.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ These can be specified by the ``x`` and ``y`` keywords.
552552
.. ipython:: python
553553
554554
df = pd.DataFrame(np.random.rand(50, 4), columns=["a", "b", "c", "d"])
555+
df["species"] = pd.Categorical(
556+
["setosa"] * 20 + ["versicolor"] * 20 + ["virginica"] * 10
557+
)
555558
556559
@savefig scatter_plot.png
557560
df.plot.scatter(x="a", y="b");
@@ -579,6 +582,21 @@ each point:
579582
df.plot.scatter(x="a", y="b", c="c", s=50);
580583
581584
585+
.. ipython:: python
586+
:suppress:
587+
588+
plt.close("all")
589+
590+
If a categorical column is passed to ``c``, then a discrete colorbar will be produced:
591+
592+
.. versionadded:: 1.3.0
593+
594+
.. ipython:: python
595+
596+
@savefig scatter_plot_categorical.png
597+
df.plot.scatter(x="a", y="b", c="species", cmap="viridis", s=50);
598+
599+
582600
.. ipython:: python
583601
:suppress:
584602

doc/source/whatsnew/v1.2.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ Deprecations
518518
- Deprecated parameter ``dtype`` of method :meth:`~Index.copy` for all :class:`Index` subclasses. Use the :meth:`~Index.astype` method instead for changing dtype (:issue:`35853`)
519519
- Deprecated parameters ``levels`` and ``codes`` in :meth:`MultiIndex.copy`. Use the :meth:`~MultiIndex.set_levels` and :meth:`~MultiIndex.set_codes` methods instead (:issue:`36685`)
520520
- Date parser functions :func:`~pandas.io.date_converters.parse_date_time`, :func:`~pandas.io.date_converters.parse_date_fields`, :func:`~pandas.io.date_converters.parse_all_fields` and :func:`~pandas.io.date_converters.generic_parser` from ``pandas.io.date_converters`` are deprecated and will be removed in a future version; use :func:`to_datetime` instead (:issue:`35741`)
521-
- :meth:`DataFrame.lookup` is deprecated and will be removed in a future version, use :meth:`DataFrame.melt` and :meth:`DataFrame.loc` instead (:issue:`18682`)
521+
- :meth:`DataFrame.lookup` is deprecated and will be removed in a future version, use :meth:`DataFrame.melt` and :meth:`DataFrame.loc` instead (:issue:`35224`)
522522
- The method :meth:`Index.to_native_types` is deprecated. Use ``.astype(str)`` instead (:issue:`28867`)
523523
- Deprecated indexing :class:`DataFrame` rows with a single datetime-like string as ``df[string]`` (given the ambiguity whether it is indexing the rows or selecting a column), use ``df.loc[string]`` instead (:issue:`36179`)
524524
- Deprecated :meth:`Index.is_all_dates` (:issue:`27744`)

doc/source/whatsnew/v1.2.2.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17-
-
17+
- Fixed regression in :meth:`~DataFrame.to_pickle` failing to create bz2/xz compressed pickle files with ``protocol=5`` (:issue:`39002`)
18+
- Fixed regression in :func:`pandas.testing.assert_series_equal` and :func:`pandas.testing.assert_frame_equal` always raising ``AssertionError`` when comparing extension dtypes (:issue:`39410`)
19+
- Fixed regression in :meth:`~DataFrame.to_csv` opening ``codecs.StreamWriter`` in binary mode instead of in text mode and ignoring user-provided ``mode`` (:issue:`39247`)
1820
-
1921

2022
.. ---------------------------------------------------------------------------

doc/source/whatsnew/v1.3.0.rst

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ Other enhancements
5252
- :meth:`DataFrame.apply` can now accept NumPy unary operators as strings, e.g. ``df.apply("sqrt")``, which was already the case for :meth:`Series.apply` (:issue:`39116`)
5353
- :meth:`DataFrame.apply` can now accept non-callable DataFrame properties as strings, e.g. ``df.apply("size")``, which was already the case for :meth:`Series.apply` (:issue:`39116`)
5454
- :meth:`Series.apply` can now accept list-like or dictionary-like arguments that aren't lists or dictionaries, e.g. ``ser.apply(np.array(["sum", "mean"]))``, which was already the case for :meth:`DataFrame.apply` (:issue:`39140`)
55-
- :meth:`.Styler.set_tooltips` allows on hover tooltips to be added to styled HTML dataframes.
56-
- :meth:`.Styler.apply` now more consistently accepts ndarray function returns, i.e. in all cases for ``axis`` is ``0, 1 or None``.
55+
- :meth:`DataFrame.plot.scatter` can now accept a categorical column as the argument to ``c`` (:issue:`12380`, :issue:`31357`)
56+
- :meth:`.Styler.set_tooltips` allows on hover tooltips to be added to styled HTML dataframes. (:issue:`39317`)
57+
- :meth:`.Styler.apply` now more consistently accepts ndarray function returns, i.e. in all cases for ``axis`` is ``0, 1 or None``. (:issue:`39359`)
58+
- :meth:`Series.loc.__getitem__` and :meth:`Series.loc.__setitem__` with :class:`MultiIndex` now raising helpful error message when indexer has too many dimensions (:issue:`35349`)
5759

5860
.. ---------------------------------------------------------------------------
5961
@@ -96,6 +98,45 @@ Preserve dtypes in :meth:`~pandas.DataFrame.combine_first`
9698
combined.dtypes
9799
98100
101+
.. _whatsnew_130.notable_bug_fixes.setitem_with_bool_casting:
102+
103+
Consistent Casting With Setting Into Boolean Series
104+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105+
106+
Setting non-boolean values into a :class:`Series with ``dtype=bool`` consistently
107+
cast to ``dtype=object`` (:issue:`38709`)
108+
109+
.. ipython:: python
110+
111+
orig = pd.Series([True, False])
112+
ser = orig.copy()
113+
ser.iloc[1] = np.nan
114+
ser2 = orig.copy()
115+
ser2.iloc[1] = 2.0
116+
117+
*pandas 1.2.x*
118+
119+
.. code-block:: ipython
120+
121+
In [1]: ser
122+
Out [1]:
123+
0 1.0
124+
1 NaN
125+
dtype: float64
126+
127+
In [2]:ser2
128+
Out [2]:
129+
0 True
130+
1 2.0
131+
dtype: object
132+
133+
*pandas 1.3.0*
134+
135+
.. ipython:: python
136+
137+
ser
138+
ser2
139+
99140
.. _whatsnew_130.api_breaking.deps:
100141

101142
Increased minimum versions for dependencies
@@ -118,7 +159,7 @@ If installed, we now require:
118159
+-----------------+-----------------+----------+---------+
119160
| pytest (dev) | 5.0.1 | | |
120161
+-----------------+-----------------+----------+---------+
121-
| mypy (dev) | 0.790 | | X |
162+
| mypy (dev) | 0.800 | | X |
122163
+-----------------+-----------------+----------+---------+
123164

124165
For `optional libraries <https://pandas.pydata.org/docs/getting_started/install.html>`_ the general recommendation is to use the latest version.
@@ -234,6 +275,7 @@ Datetimelike
234275
- Bug in constructing a :class:`DataFrame` or :class:`Series` with mismatched ``datetime64`` data and ``timedelta64`` dtype, or vice-versa, failing to raise ``TypeError`` (:issue:`38575`, :issue:`38764`, :issue:`38792`)
235276
- Bug in constructing a :class:`Series` or :class:`DataFrame` with a ``datetime`` object out of bounds for ``datetime64[ns]`` dtype or a ``timedelta`` object out of bounds for ``timedelta64[ns]`` dtype (:issue:`38792`, :issue:`38965`)
236277
- Bug in :meth:`DatetimeIndex.intersection`, :meth:`DatetimeIndex.symmetric_difference`, :meth:`PeriodIndex.intersection`, :meth:`PeriodIndex.symmetric_difference` always returning object-dtype when operating with :class:`CategoricalIndex` (:issue:`38741`)
278+
- Bug in :class:`DataFrame` constructor reordering element when construction from datetime ndarray with dtype not ``"datetime64[ns]"`` (:issue:`39422`)
237279
- Bug in :meth:`Series.where` incorrectly casting ``datetime64`` values to ``int64`` (:issue:`37682`)
238280
- Bug in :class:`Categorical` incorrectly typecasting ``datetime`` object to ``Timestamp`` (:issue:`38878`)
239281
- Bug in comparisons between :class:`Timestamp` object and ``datetime64`` objects just outside the implementation bounds for nanosecond ``datetime64`` (:issue:`39221`)
@@ -290,11 +332,14 @@ Indexing
290332
- Bug in :meth:`DataFrame.loc.__setitem__` raising ValueError when expanding unique column for :class:`DataFrame` with duplicate columns (:issue:`38521`)
291333
- Bug in :meth:`DataFrame.iloc.__setitem__` and :meth:`DataFrame.loc.__setitem__` with mixed dtypes when setting with a dictionary value (:issue:`38335`)
292334
- Bug in :meth:`DataFrame.__setitem__` not raising ``ValueError`` when right hand side is a :class:`DataFrame` with wrong number of columns (:issue:`38604`)
335+
- Bug in :meth:`Series.__setitem__` raising ``ValueError`` when setting a :class:`Series` with a scalar indexer (:issue:`38303`)
293336
- Bug in :meth:`DataFrame.loc` dropping levels of :class:`MultiIndex` when :class:`DataFrame` used as input has only one row (:issue:`10521`)
294337
- Bug in :meth:`DataFrame.__getitem__` and :meth:`Series.__getitem__` always raising ``KeyError`` when slicing with existing strings an :class:`Index` with milliseconds (:issue:`33589`)
295338
- Bug in setting ``timedelta64`` values into numeric :class:`Series` failing to cast to object dtype (:issue:`39086`)
296339
- Bug in setting :class:`Interval` values into a :class:`Series` or :class:`DataFrame` with mismatched :class:`IntervalDtype` incorrectly casting the new values to the existing dtype (:issue:`39120`)
340+
- Bug in setting ``datetime64`` values into a :class:`Series` with integer-dtype incorrect casting the datetime64 values to integers (:issue:`39266`)
297341
- Bug in incorrectly raising in :meth:`Index.insert`, when setting a new column that cannot be held in the existing ``frame.columns``, or in :meth:`Series.reset_index` or :meth:`DataFrame.reset_index` instead of casting to a compatible dtype (:issue:`39068`)
342+
- Bug in :meth:`RangeIndex.append` where a single object of length 1 was concatenated incorrectly (:issue:`39401`)
298343

299344
Missing
300345
^^^^^^^
@@ -326,6 +371,7 @@ I/O
326371
- Bug in :func:`to_hdf` raising ``KeyError`` when trying to apply for subclasses of ``DataFrame`` or ``Series`` (:issue:`33748`)
327372
- Bug in :meth:`~HDFStore.put` raising a wrong ``TypeError`` when saving a DataFrame with non-string dtype (:issue:`34274`)
328373
- Bug in :func:`json_normalize` resulting in the first element of a generator object not being included in the returned ``DataFrame`` (:issue:`35923`)
374+
- Bug in :func:`read_csv` apllying thousands separator to date columns when column should be parsed for dates and ``usecols`` is specified for ``engine="python"`` (:issue:`39365`)
329375
- Bug in :func:`read_excel` forward filling :class:`MultiIndex` names with multiple header and index columns specified (:issue:`34673`)
330376
- :func:`read_excel` now respects :func:`set_option` (:issue:`34252`)
331377
- Bug in :func:`read_csv` not switching ``true_values`` and ``false_values`` for nullable ``boolean`` dtype (:issue:`34655`)
@@ -342,7 +388,7 @@ Plotting
342388
^^^^^^^^
343389

344390
- Bug in :func:`scatter_matrix` raising when 2d ``ax`` argument passed (:issue:`16253`)
345-
-
391+
- Prevent warnings when matplotlib's ``constrained_layout`` is enabled (:issue:`25261`)
346392
-
347393

348394
Groupby/resample/rolling
@@ -364,7 +410,7 @@ Reshaping
364410
- Bug in :func:`join` over :class:`MultiIndex` returned wrong result, when one of both indexes had only one level (:issue:`36909`)
365411
- :meth:`merge_asof` raises ``ValueError`` instead of cryptic ``TypeError`` in case of non-numerical merge columns (:issue:`29130`)
366412
- Bug in :meth:`DataFrame.join` not assigning values correctly when having :class:`MultiIndex` where at least one dimension is from dtype ``Categorical`` with non-alphabetically sorted categories (:issue:`38502`)
367-
- :meth:`Series.value_counts` returns keys in original order (:issue:`12679`, :issue:`11227`)
413+
- :meth:`Series.value_counts` and :meth:`Series.mode` return consistent keys in original order (:issue:`12679`, :issue:`11227` and :issue:`39007`)
368414
- Bug in :meth:`DataFrame.apply` would give incorrect results when used with a string argument and ``axis=1`` when the axis argument was not supported and now raises a ``ValueError`` instead (:issue:`39211`)
369415
-
370416

@@ -386,6 +432,7 @@ Other
386432
^^^^^
387433
- Bug in :class:`Index` constructor sometimes silently ignorning a specified ``dtype`` (:issue:`38879`)
388434
- Bug in constructing a :class:`Series` from a list and a :class:`PandasDtype` (:issue:`39357`)
435+
- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`)
389436
-
390437

391438
.. ---------------------------------------------------------------------------

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- flake8
2424
- flake8-comprehensions>=3.1.0 # used by flake8, linting of unnecessary comprehensions
2525
- isort>=5.2.1 # check that imports are in the right order
26-
- mypy=0.790
26+
- mypy=0.800
2727
- pre-commit>=2.9.2
2828
- pycodestyle # used by flake8
2929
- pyupgrade

0 commit comments

Comments
 (0)