Skip to content

Commit 5088cce

Browse files
authored
Merge branch 'main' into pylint-48855-C-type-disallowed-name
2 parents cd47c4d + 3872572 commit 5088cce

40 files changed

+238
-1265
lines changed

asv_bench/benchmarks/io/sql.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def setup(self, connection):
3838
},
3939
index=tm.makeStringIndex(N),
4040
)
41-
self.df.loc[1000:3000, "float_with_nan"] = np.nan
41+
self.df.iloc[1000:3000, 1] = np.nan
4242
self.df["date"] = self.df["datetime"].dt.date
4343
self.df["time"] = self.df["datetime"].dt.time
4444
self.df["datetime_string"] = self.df["datetime"].astype(str)
@@ -88,7 +88,7 @@ def setup(self, connection, dtype):
8888
},
8989
index=tm.makeStringIndex(N),
9090
)
91-
self.df.loc[1000:3000, "float_with_nan"] = np.nan
91+
self.df.iloc[1000:3000, 1] = np.nan
9292
self.df["date"] = self.df["datetime"].dt.date
9393
self.df["time"] = self.df["datetime"].dt.time
9494
self.df["datetime_string"] = self.df["datetime"].astype(str)
@@ -117,7 +117,7 @@ def setup(self):
117117
},
118118
index=tm.makeStringIndex(N),
119119
)
120-
self.df.loc[1000:3000, "float_with_nan"] = np.nan
120+
self.df.iloc[1000:3000, 1] = np.nan
121121
self.df["date"] = self.df["datetime"].dt.date
122122
self.df["time"] = self.df["datetime"].dt.time
123123
self.df["datetime_string"] = self.df["datetime"].astype(str)
@@ -164,7 +164,7 @@ def setup(self, dtype):
164164
},
165165
index=tm.makeStringIndex(N),
166166
)
167-
self.df.loc[1000:3000, "float_with_nan"] = np.nan
167+
self.df.iloc[1000:3000, 1] = np.nan
168168
self.df["date"] = self.df["datetime"].dt.date
169169
self.df["time"] = self.df["datetime"].dt.time
170170
self.df["datetime_string"] = self.df["datetime"].astype(str)

doc/source/getting_started/intro_tutorials/09_timeseries.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ I want to add a new column to the ``DataFrame`` containing only the month of the
144144
145145
By using ``Timestamp`` objects for dates, a lot of time-related
146146
properties are provided by pandas. For example the ``month``, but also
147-
``year``, ``weekofyear``, ``quarter``,… All of these properties are
147+
``year``, ``quarter``,… All of these properties are
148148
accessible by the ``dt`` accessor.
149149

150150
.. raw:: html

doc/source/reference/indexing.rst

-2
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,6 @@ Time/date components
343343
DatetimeIndex.timetz
344344
DatetimeIndex.dayofyear
345345
DatetimeIndex.day_of_year
346-
DatetimeIndex.weekofyear
347-
DatetimeIndex.week
348346
DatetimeIndex.dayofweek
349347
DatetimeIndex.day_of_week
350348
DatetimeIndex.weekday

doc/source/reference/series.rst

-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ Datetime properties
311311
Series.dt.second
312312
Series.dt.microsecond
313313
Series.dt.nanosecond
314-
Series.dt.week
315-
Series.dt.weekofyear
316314
Series.dt.dayofweek
317315
Series.dt.day_of_week
318316
Series.dt.weekday

doc/source/user_guide/categorical.rst

+2-12
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,6 @@ Renaming categories is done by using the
353353

354354
In contrast to R's ``factor``, categorical data can have categories of other types than string.
355355

356-
.. note::
357-
358-
Be aware that assigning new categories is an inplace operation, while most other operations
359-
under ``Series.cat`` per default return a new ``Series`` of dtype ``category``.
360-
361356
Categories must be unique or a ``ValueError`` is raised:
362357

363358
.. ipython:: python
@@ -952,7 +947,6 @@ categorical (categories and ordering). So if you read back the CSV file you have
952947
relevant columns back to ``category`` and assign the right categories and categories ordering.
953948

954949
.. ipython:: python
955-
:okwarning:
956950
957951
import io
958952
@@ -969,8 +963,8 @@ relevant columns back to ``category`` and assign the right categories and catego
969963
df2["cats"]
970964
# Redo the category
971965
df2["cats"] = df2["cats"].astype("category")
972-
df2["cats"].cat.set_categories(
973-
["very bad", "bad", "medium", "good", "very good"], inplace=True
966+
df2["cats"] = df2["cats"].cat.set_categories(
967+
["very bad", "bad", "medium", "good", "very good"]
974968
)
975969
df2.dtypes
976970
df2["cats"]
@@ -1162,16 +1156,12 @@ Constructing a ``Series`` from a ``Categorical`` will not copy the input
11621156
change the original ``Categorical``:
11631157

11641158
.. ipython:: python
1165-
:okwarning:
11661159
11671160
cat = pd.Categorical([1, 2, 3, 10], categories=[1, 2, 3, 4, 10])
11681161
s = pd.Series(cat, name="cat")
11691162
cat
11701163
s.iloc[0:2] = 10
11711164
cat
1172-
df = pd.DataFrame(s)
1173-
df["cat"].cat.categories = [1, 2, 3, 4, 5]
1174-
cat
11751165
11761166
Use ``copy=True`` to prevent such a behaviour or simply don't reuse ``Categoricals``:
11771167

doc/source/whatsnew/v0.15.0.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ For full docs, see the :ref:`categorical introduction <categorical>` and the
7070
:ref:`API documentation <api.arrays.categorical>`.
7171

7272
.. ipython:: python
73-
:okwarning:
7473
7574
df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6],
7675
"raw_grade": ['a', 'b', 'b', 'a', 'a', 'e']})
@@ -79,7 +78,7 @@ For full docs, see the :ref:`categorical introduction <categorical>` and the
7978
df["grade"]
8079
8180
# Rename the categories
82-
df["grade"].cat.categories = ["very good", "good", "very bad"]
81+
df["grade"] = df["grade"].cat.rename_categories(["very good", "good", "very bad"])
8382
8483
# Reorder the categories and simultaneously add the missing categories
8584
df["grade"] = df["grade"].cat.set_categories(["very bad", "bad",

doc/source/whatsnew/v0.19.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ Individual columns can be parsed as a ``Categorical`` using a dict specification
271271
such as :func:`to_datetime`.
272272

273273
.. ipython:: python
274-
:okwarning:
275274
276275
df = pd.read_csv(StringIO(data), dtype="category")
277276
df.dtypes
278277
df["col3"]
279-
df["col3"].cat.categories = pd.to_numeric(df["col3"].cat.categories)
278+
new_categories = pd.to_numeric(df["col3"].cat.categories)
279+
df["col3"] = df["col3"].cat.rename_categories(new_categories)
280280
df["col3"]
281281
282282
.. _whatsnew_0190.enhancements.union_categoricals:

doc/source/whatsnew/v2.0.0.rst

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Other enhancements
4949
- Fix ``test`` optional_extra by adding missing test package ``pytest-asyncio`` (:issue:`48361`)
5050
- :func:`DataFrame.astype` exception message thrown improved to include column name when type conversion is not possible. (:issue:`47571`)
5151
- :meth:`DataFrame.to_json` now supports a ``mode`` keyword with supported inputs 'w' and 'a'. Defaulting to 'w', 'a' can be used when lines=True and orient='records' to append record oriented json lines to an existing json file. (:issue:`35849`)
52+
- Added ``name`` parameter to :meth:`IntervalIndex.from_breaks`, :meth:`IntervalIndex.from_arrays` and :meth:`IntervalIndex.from_tuples` (:issue:`48911`)
5253

5354
.. ---------------------------------------------------------------------------
5455
.. _whatsnew_200.notable_bug_fixes:
@@ -170,6 +171,7 @@ Removal of prior version deprecations/changes
170171
- Removed deprecated :meth:`Index.to_native_types`, use ``obj.astype(str)`` instead (:issue:`36418`)
171172
- Removed deprecated :meth:`Series.iteritems`, :meth:`DataFrame.iteritems`, use ``obj.items`` instead (:issue:`45321`)
172173
- Removed deprecated :meth:`DatetimeIndex.union_many` (:issue:`45018`)
174+
- Removed deprecated ``weekofyear`` and ``week`` attributes of :class:`DatetimeArray`, :class:`DatetimeIndex` and ``dt`` accessor in favor of ``isocalendar().week`` (:issue:`33595`)
173175
- Removed deprecated :meth:`RangeIndex._start`, :meth:`RangeIndex._stop`, :meth:`RangeIndex._step`, use ``start``, ``stop``, ``step`` instead (:issue:`30482`)
174176
- Removed deprecated :meth:`DatetimeIndex.to_perioddelta`, Use ``dtindex - dtindex.to_period(freq).to_timestamp()`` instead (:issue:`34853`)
175177
- Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
@@ -236,6 +238,7 @@ Removal of prior version deprecations/changes
236238
- Removed deprecated :meth:`Timedelta.delta`, :meth:`Timedelta.is_populated`, and :attr:`Timedelta.freq` (:issue:`46430`, :issue:`46476`)
237239
- Removed deprecated :meth:`Categorical.replace`, use :meth:`Series.replace` instead (:issue:`44929`)
238240
- Removed the ``numeric_only`` keyword from :meth:`Categorical.min` and :meth:`Categorical.max` in favor of ``skipna`` (:issue:`48821`)
241+
- Changed behavior of :meth:`DataFrame.median` and :meth:`DataFrame.mean` with ``numeric_only=None`` to not exclude datetime-like columns THIS NOTE WILL BE IRRELEVANT ONCE ``numeric_only=None`` DEPRECATION IS ENFORCED (:issue:`29941`)
239242
- Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`)
240243
- Removed ``.ExponentialMovingWindow.vol`` (:issue:`39220`)
241244
- Removed :meth:`Index.get_value` and :meth:`Index.set_value` (:issue:`33907`, :issue:`28621`)
@@ -256,7 +259,10 @@ Removal of prior version deprecations/changes
256259
- Enforced disallowing passing an integer ``fill_value`` to :meth:`DataFrame.shift` and :meth:`Series.shift`` with datetime64, timedelta64, or period dtypes (:issue:`32591`)
257260
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
258261
- Enforced disallowing a tuple of column labels into :meth:`.DataFrameGroupBy.__getitem__` (:issue:`30546`)
262+
- Enforced disallowing setting values with ``.loc`` using a positional slice. Use ``.loc`` with labels or ``.iloc`` with positions instead (:issue:`31840`)
259263
- Removed setting Categorical._codes directly (:issue:`41429`)
264+
- Removed setting Categorical.categories directly (:issue:`47834`)
265+
- Removed argument ``inplace`` from :meth:`Categorical.add_categories`, :meth:`Categorical.remove_categories`, :meth:`Categorical.set_categories`, :meth:`Categorical.rename_categories`, :meth:`Categorical.reorder_categories`, :meth:`Categorical.set_ordered`, :meth:`Categorical.as_ordered`, :meth:`Categorical.as_unordered` (:issue:`37981`, :issue:`41118`, :issue:`41133`, :issue:`47834`)
260266
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)
261267
- Renamed ``fname`` to ``path`` in :meth:`DataFrame.to_parquet`, :meth:`DataFrame.to_stata` and :meth:`DataFrame.to_feather` (:issue:`30338`)
262268
- Enforced disallowing indexing a :class:`Series` with a single item list with a slice (e.g. ``ser[[slice(0, 2)]]``). Either convert the list to tuple, or pass the slice directly instead (:issue:`31333`)
@@ -269,7 +275,9 @@ Removal of prior version deprecations/changes
269275
- Changed behavior of :class:`DataFrame` constructor when passed a ``dtype`` (other than int) that the data cannot be cast to; it now raises instead of silently ignoring the dtype (:issue:`41733`)
270276
- Changed the behavior of :class:`Series` constructor, it will no longer infer a datetime64 or timedelta64 dtype from string entries (:issue:`41731`)
271277
- Changed behavior of :class:`Index` constructor when passed a ``SparseArray`` or ``SparseDtype`` to retain that dtype instead of casting to ``numpy.ndarray`` (:issue:`43930`)
278+
- Removed the deprecated ``base`` and ``loffset`` arguments from :meth:`pandas.DataFrame.resample`, :meth:`pandas.Series.resample` and :class:`pandas.Grouper`. Use ``offset`` or ``origin`` instead (:issue:`31809`)
272279
- Changed behavior of :meth:`DataFrame.any` and :meth:`DataFrame.all` with ``bool_only=True``; object-dtype columns with all-bool values will no longer be included, manually cast to ``bool`` dtype first (:issue:`46188`)
280+
- Enforced deprecation of silently dropping columns that raised a ``TypeError`` in :class:`Series.transform` and :class:`DataFrame.transform` when used with a list or dictionary (:issue:`43740`)
273281
-
274282

275283
.. ---------------------------------------------------------------------------

pandas/_libs/tslibs/parsing.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,11 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None:
10111011
break
10121012

10131013
# Only consider it a valid guess if we have a year, month and day,
1014-
# unless it's %Y which is both common and unambiguous.
1014+
# unless it's %Y or %Y-%m which conform with ISO8601. Note that we don't
1015+
# make an exception for %Y%m because it's explicitly not considered ISO8601.
10151016
if (
10161017
len({'year', 'month', 'day'} & found_attrs) != 3
1017-
and format_guess != ['%Y']
1018+
and format_guess not in (['%Y'], ['%Y', None, '%m'])
10181019
):
10191020
return None
10201021

pandas/core/apply.py

+1-26
Original file line numberDiff line numberDiff line change
@@ -266,34 +266,9 @@ def transform_dict_like(self, func):
266266
func = self.normalize_dictlike_arg("transform", obj, func)
267267

268268
results: dict[Hashable, DataFrame | Series] = {}
269-
failed_names = []
270-
all_type_errors = True
271269
for name, how in func.items():
272270
colg = obj._gotitem(name, ndim=1)
273-
try:
274-
results[name] = colg.transform(how, 0, *args, **kwargs)
275-
except Exception as err:
276-
if str(err) in {
277-
"Function did not transform",
278-
"No transform functions were provided",
279-
}:
280-
raise err
281-
else:
282-
if not isinstance(err, TypeError):
283-
all_type_errors = False
284-
failed_names.append(name)
285-
# combine results
286-
if not results:
287-
klass = TypeError if all_type_errors else ValueError
288-
raise klass("Transform function failed")
289-
if len(failed_names) > 0:
290-
warnings.warn(
291-
f"{failed_names} did not transform successfully. If any error is "
292-
f"raised, this will raise in a future version of pandas. "
293-
f"Drop these columns/ops to avoid this warning.",
294-
FutureWarning,
295-
stacklevel=find_stack_level(),
296-
)
271+
results[name] = colg.transform(how, 0, *args, **kwargs)
297272
return concat(results, axis=1)
298273

299274
def transform_str_or_callable(self, func) -> DataFrame | Series:

0 commit comments

Comments
 (0)