Skip to content

Commit 8609ea5

Browse files
Merge branch 'main' into scatter_color
2 parents b91e635 + 1165859 commit 8609ea5

File tree

7 files changed

+42
-10
lines changed

7 files changed

+42
-10
lines changed

ci/code_checks.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7070
--format=actions \
7171
-i ES01 `# For now it is ok if docstrings are missing the extended summary` \
7272
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
73-
-i "pandas.DataFrame.max RT03" \
74-
-i "pandas.DataFrame.mean RT03" \
75-
-i "pandas.DataFrame.median RT03" \
76-
-i "pandas.DataFrame.min RT03" \
7773
-i "pandas.DataFrame.plot PR02" \
7874
-i "pandas.Grouper PR02" \
7975
-i "pandas.MultiIndex.append PR07,SA01" \
@@ -166,7 +162,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
166162
-i "pandas.Series.product RT03" \
167163
-i "pandas.Series.reorder_levels RT03,SA01" \
168164
-i "pandas.Series.sem PR01,RT03,SA01" \
169-
-i "pandas.Series.skew RT03,SA01" \
165+
-i "pandas.Series.skew SA01" \
170166
-i "pandas.Series.sparse PR01,SA01" \
171167
-i "pandas.Series.sparse.density SA01" \
172168
-i "pandas.Series.sparse.fill_value SA01" \

doc/source/getting_started/intro_tutorials/04_plotting.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ How do I create plots in pandas?
3232
air_quality.head()
3333
3434
.. note::
35-
The usage of the ``index_col`` and ``parse_dates`` parameters of the ``read_csv`` function to define the first (0th) column as
36-
index of the resulting ``DataFrame`` and convert the dates in the column to :class:`Timestamp` objects, respectively.
35+
The ``index_col=0`` and ``parse_dates=True`` parameters passed to the ``read_csv`` function define
36+
the first (0th) column as index of the resulting ``DataFrame`` and convert the dates in the column
37+
to :class:`Timestamp` objects, respectively.
38+
3739

3840
.. raw:: html
3941

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ MultiIndex
556556
- :func:`DataFrame.loc` with ``axis=0`` and :class:`MultiIndex` when setting a value adds extra columns (:issue:`58116`)
557557
- :meth:`DataFrame.melt` would not accept multiple names in ``var_name`` when the columns were a :class:`MultiIndex` (:issue:`58033`)
558558
- :meth:`MultiIndex.insert` would not insert NA value correctly at unified location of index -1 (:issue:`59003`)
559+
- :func:`MultiIndex.get_level_values` accessing a :class:`DatetimeIndex` does not carry the frequency attribute along (:issue:`58327`, :issue:`57949`)
559560
-
560561

561562
I/O

pandas/core/arrays/datetimelike.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
ScalarIndexer,
6666
Self,
6767
SequenceIndexer,
68+
TakeIndexer,
6869
TimeAmbiguous,
6970
TimeNonexistent,
7071
npt,
@@ -2340,6 +2341,27 @@ def interpolate(
23402341
return self
23412342
return type(self)._simple_new(out_data, dtype=self.dtype)
23422343

2344+
def take(
2345+
self,
2346+
indices: TakeIndexer,
2347+
*,
2348+
allow_fill: bool = False,
2349+
fill_value: Any = None,
2350+
axis: AxisInt = 0,
2351+
) -> Self:
2352+
result = super().take(
2353+
indices=indices, allow_fill=allow_fill, fill_value=fill_value, axis=axis
2354+
)
2355+
2356+
indices = np.asarray(indices, dtype=np.intp)
2357+
maybe_slice = lib.maybe_indices_to_slice(indices, len(self))
2358+
2359+
if isinstance(maybe_slice, slice):
2360+
freq = self._get_getitem_freq(maybe_slice)
2361+
result._freq = freq
2362+
2363+
return result
2364+
23432365
# --------------------------------------------------------------
23442366
# Unsorted
23452367

pandas/core/frame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4473,7 +4473,7 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
44734473
or punctuations (besides underscores) or starting with digits must be
44744474
surrounded by backticks. (For example, a column named "Area (cm^2)" would
44754475
be referenced as ```Area (cm^2)```). Column names which are Python keywords
4476-
(like "list", "for", "import", etc) cannot be used.
4476+
(like "if", "for", "import", etc) cannot be used.
44774477
44784478
For example, if one of your columns is called ``a a`` and you want
44794479
to sum it with ``b``, your query should be ```a a` + b``.
@@ -4554,8 +4554,8 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
45544554
For example, ```it's` > `that's``` will raise an error,
45554555
as it forms a quoted string (``'s > `that'``) with a backtick inside.
45564556
4557-
See also the Python documentation about lexical analysis
4558-
(https://docs.python.org/3/reference/lexical_analysis.html)
4557+
See also the `Python documentation about lexical analysis
4558+
<https://docs.python.org/3/reference/lexical_analysis.html>`__
45594559
in combination with the source code in :mod:`pandas.core.computation.parsing`.
45604560
45614561
Examples

pandas/core/generic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11777,6 +11777,8 @@ def last_valid_index(self) -> Hashable:
1177711777
Returns
1177811778
-------
1177911779
{name1} or scalar\
11780+
11781+
Value containing the calculation referenced in the description.\
1178011782
{see_also}\
1178111783
{examples}
1178211784
"""

pandas/tests/indexes/multi/test_get_level_values.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,12 @@ def test_values_loses_freq_of_underlying_index():
122122
midx.values
123123
assert idx.freq is not None
124124
tm.assert_index_equal(idx, expected)
125+
126+
127+
def test_get_level_values_gets_frequency_correctly():
128+
# GH#57949 GH#58327
129+
datetime_index = date_range(start=pd.to_datetime("1/1/2018"), periods=4, freq="YS")
130+
other_index = ["A"]
131+
multi_index = MultiIndex.from_product([datetime_index, other_index])
132+
133+
assert multi_index.get_level_values(0).freq == datetime_index.freq

0 commit comments

Comments
 (0)