Skip to content

Commit e4012f0

Browse files
committed
FIX: Fix docstring formatting, missing imports, and undefined variables
1 parent d82c621 commit e4012f0

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

pandas/core/generic.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,17 @@
182182
Window,
183183
)
184184

185+
# Import ExcelFormatter at runtime since it's used in to_excel method
186+
from pandas.io.formats.excel import ExcelFormatter
185187
from pandas.io.formats.format import (
186188
DataFrameFormatter,
187189
DataFrameRenderer,
188190
)
189191
from pandas.io.formats.printing import pprint_thing
190192

191193
if TYPE_CHECKING:
192-
from collections.abc import Callable
193194
from collections.abc import (
195+
Callable,
194196
Hashable,
195197
Iterator,
196198
Mapping,
@@ -202,15 +204,17 @@
202204

203205
from pandas import (
204206
DataFrame,
205-
ExcelWriter,
206207
HDFStore,
207208
Series,
208209
)
209210
from pandas.core.indexers.objects import BaseIndexer
210211
from pandas.core.resample import Resampler
211212

213+
# Import ExcelWriter at runtime since it's used in to_excel method
212214
import textwrap
213215

216+
from pandas import ExcelWriter
217+
214218
# goal is to be able to define the docs close to function, while still being
215219
# able to share
216220
_shared_docs = {**_shared_docs}
@@ -773,6 +777,7 @@ def _set_axis(self, axis: AxisInt, labels: AnyArrayLike | list) -> None:
773777
"""
774778
labels = ensure_index(labels)
775779
self._mgr.set_axis(axis, labels)
780+
776781
@final
777782
@doc(klass=_shared_doc_kwargs["klass"])
778783
def droplevel(self, level: IndexLabel, axis: Axis = 0) -> Self:
@@ -1514,6 +1519,7 @@ def __bool__(self) -> NoReturn:
15141519
f"The truth value of a {type(self).__name__} is ambiguous. "
15151520
"Use a.empty, a.bool(), a.item(), a.any() or a.all()."
15161521
)
1522+
15171523
@final
15181524
def abs(self) -> Self:
15191525
"""
@@ -2265,7 +2271,7 @@ def to_excel(
22652271
22662272
Examples
22672273
--------
2268-
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
2274+
>>> df = pd.DataFrame({{"A": [1, 2, 3], "B": [4, 5, 6]}})
22692275
>>> df.to_excel("pandas_simple.xlsx")
22702276
>>> df.to_excel("pandas_simple.xlsx", engine="openpyxl")
22712277
"""
@@ -2279,11 +2285,7 @@ def to_excel(
22792285
excel_writer = ExcelWriter(
22802286
excel_writer,
22812287
engine=engine,
2282-
mode=mode,
2283-
if_sheet_exists=if_sheet_exists,
22842288
engine_kwargs=engine_kwargs,
2285-
date_format=date_format,
2286-
datetime_format=datetime_format,
22872289
storage_options=storage_options,
22882290
)
22892291

@@ -5616,6 +5618,7 @@ def f(x) -> bool:
56165618
return self.loc(axis=axis)[values]
56175619
else:
56185620
raise TypeError("Must pass either `items`, `like`, or `regex`")
5621+
56195622
@final
56205623
def head(self, n: int = 5) -> Self:
56215624
"""
@@ -6088,7 +6091,8 @@ def __finalize__(self, other, method: str | None = None, **kwargs) -> Self:
60886091
----------
60896092
other : the object from which to get the attributes that we are going
60906093
to propagate. If ``other`` has an ``input_objs`` attribute, then
6091-
this attribute must contain an iterable of objects, each with an ``attrs`` attribute.
6094+
this attribute must contain an iterable of objects, each with an
6095+
``attrs`` attribute.
60926096
method : str, optional
60936097
A passed method name providing context on where ``__finalize__``
60946098
was called.
@@ -9693,6 +9697,7 @@ def align(
96939697
left = left.__finalize__(self)
96949698
right = right.__finalize__(other)
96959699
return left, right
9700+
96969701
@final
96979702
def _align_frame(
96989703
self,
@@ -12811,6 +12816,8 @@ def last_valid_index(self) -> Hashable:
1281112816
The required number of valid values to perform the operation. If fewer than
1281212817
``min_count`` non-NA values are present the result will be NA.
1281312818
"""
12819+
12820+
1281412821
def make_doc(name: str, ndim: int) -> str:
1281512822
"""
1281612823
Generate the docstring for a Series/DataFrame reduction.
@@ -13177,4 +13184,4 @@ def make_doc(name: str, ndim: int) -> str:
1317713184
examples=examples,
1317813185
**kwargs,
1317913186
)
13180-
return docstr
13187+
return docstr

pandas/tests/io/excel/test_xlsxwriter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
import pandas as pd
67
from pandas import DataFrame
78

89
from pandas.io.excel import ExcelWriter
@@ -179,4 +180,4 @@ def test_to_excel_autofilter_multiindex_no_merge_xlsxwriter(tmp_excel):
179180
assert ws.auto_filter is not None
180181
assert ws.auto_filter.ref is not None
181182
finally:
182-
wb.close()
183+
wb.close()

0 commit comments

Comments
 (0)