|
112 | 112 | if TYPE_CHECKING:
|
113 | 113 | from pandas._libs.tslibs import BaseOffset
|
114 | 114 |
|
| 115 | + from pandas.core.frame import DataFrame |
115 | 116 | from pandas.core.resample import Resampler
|
116 | 117 | from pandas.core.series import Series
|
117 | 118 | from pandas.core.window.indexers import BaseIndexer
|
|
130 | 131 | )
|
131 | 132 |
|
132 | 133 |
|
133 |
| -def _single_replace(self, to_replace, method, inplace, limit): |
| 134 | +def _single_replace(self: "Series", to_replace, method, inplace, limit): |
134 | 135 | """
|
135 | 136 | Replaces values in a Series using the fill method specified when no
|
136 | 137 | replacement value is given in the replace method
|
@@ -541,6 +542,7 @@ def _get_cleaned_column_resolvers(self) -> Dict[str, ABCSeries]:
|
541 | 542 | from pandas.core.computation.parsing import clean_column_name
|
542 | 543 |
|
543 | 544 | if isinstance(self, ABCSeries):
|
| 545 | + self = cast("Series", self) |
544 | 546 | return {clean_column_name(self.name): self}
|
545 | 547 |
|
546 | 548 | return {
|
@@ -1995,9 +1997,10 @@ def _repr_data_resource_(self):
|
1995 | 1997 | """
|
1996 | 1998 | if config.get_option("display.html.table_schema"):
|
1997 | 1999 | data = self.head(config.get_option("display.max_rows"))
|
1998 |
| - payload = json.loads( |
1999 |
| - data.to_json(orient="table"), object_pairs_hook=collections.OrderedDict |
2000 |
| - ) |
| 2000 | + |
| 2001 | + as_json = data.to_json(orient="table") |
| 2002 | + as_json = cast(str, as_json) |
| 2003 | + payload = json.loads(as_json, object_pairs_hook=collections.OrderedDict) |
2001 | 2004 | return payload
|
2002 | 2005 |
|
2003 | 2006 | # ----------------------------------------------------------------------
|
@@ -3113,6 +3116,7 @@ def to_latex(
|
3113 | 3116 | if multirow is None:
|
3114 | 3117 | multirow = config.get_option("display.latex.multirow")
|
3115 | 3118 |
|
| 3119 | + self = cast("DataFrame", self) |
3116 | 3120 | formatter = DataFrameFormatter(
|
3117 | 3121 | self,
|
3118 | 3122 | columns=columns,
|
@@ -3830,7 +3834,7 @@ def _check_setitem_copy(self, stacklevel=4, t="setting", force=False):
|
3830 | 3834 | # the copy weakref
|
3831 | 3835 | if self._is_copy is not None and not isinstance(self._is_copy, str):
|
3832 | 3836 | r = self._is_copy()
|
3833 |
| - if not gc.get_referents(r) or r.shape == self.shape: |
| 3837 | + if not gc.get_referents(r) or (r is not None and r.shape == self.shape): |
3834 | 3838 | self._is_copy = None
|
3835 | 3839 | return
|
3836 | 3840 |
|
@@ -6684,6 +6688,7 @@ def replace(
|
6684 | 6688 | return self.apply(
|
6685 | 6689 | _single_replace, args=(to_replace, method, inplace, limit)
|
6686 | 6690 | )
|
| 6691 | + self = cast("Series", self) |
6687 | 6692 | return _single_replace(self, to_replace, method, inplace, limit)
|
6688 | 6693 |
|
6689 | 6694 | if not is_dict_like(to_replace):
|
@@ -7265,10 +7270,13 @@ def asof(self, where, subset=None):
|
7265 | 7270 | nulls = self.isna() if is_series else self[subset].isna().any(1)
|
7266 | 7271 | if nulls.all():
|
7267 | 7272 | if is_series:
|
| 7273 | + self = cast("Series", self) |
7268 | 7274 | return self._constructor(np.nan, index=where, name=self.name)
|
7269 | 7275 | elif is_list:
|
| 7276 | + self = cast("DataFrame", self) |
7270 | 7277 | return self._constructor(np.nan, index=where, columns=self.columns)
|
7271 | 7278 | else:
|
| 7279 | + self = cast("DataFrame", self) |
7272 | 7280 | return self._constructor_sliced(
|
7273 | 7281 | np.nan, index=self.columns, name=where[0]
|
7274 | 7282 | )
|
|
0 commit comments