|
85 | 85 | from pandas.core.dtypes.inference import is_hashable
|
86 | 86 | from pandas.core.dtypes.missing import isna, notna
|
87 | 87 |
|
88 |
| -import pandas as pd |
89 | 88 | from pandas.core import arraylike, indexing, missing, nanops
|
90 | 89 | import pandas.core.algorithms as algos
|
91 | 90 | from pandas.core.arrays import ExtensionArray
|
|
106 | 105 | from pandas.core.internals import ArrayManager, BlockManager
|
107 | 106 | from pandas.core.missing import find_valid_index
|
108 | 107 | from pandas.core.ops import align_method_FRAME
|
| 108 | +from pandas.core.reshape.concat import concat |
109 | 109 | from pandas.core.shared_docs import _shared_docs
|
110 | 110 | from pandas.core.sorting import get_indexer_indexer
|
111 | 111 | from pandas.core.window import Expanding, ExponentialMovingWindow, Rolling, Window
|
@@ -5304,7 +5304,11 @@ def sample(
|
5304 | 5304 | "when sampling from a Series."
|
5305 | 5305 | )
|
5306 | 5306 |
|
5307 |
| - weights = pd.Series(weights, dtype="float64") |
| 5307 | + if isinstance(self, ABCSeries): |
| 5308 | + func = self._constructor |
| 5309 | + else: |
| 5310 | + func = self._constructor_sliced |
| 5311 | + weights = func(weights, dtype="float64") |
5308 | 5312 |
|
5309 | 5313 | if len(weights) != axis_length:
|
5310 | 5314 | raise ValueError(
|
@@ -5890,7 +5894,7 @@ def astype(
|
5890 | 5894 | return self.copy()
|
5891 | 5895 |
|
5892 | 5896 | # GH 19920: retain column metadata after concat
|
5893 |
| - result = pd.concat(results, axis=1, copy=False) |
| 5897 | + result = concat(results, axis=1, copy=False) |
5894 | 5898 | result.columns = self.columns
|
5895 | 5899 | return result
|
5896 | 5900 |
|
@@ -6254,7 +6258,7 @@ def convert_dtypes(
|
6254 | 6258 | )
|
6255 | 6259 | for col_name, col in self.items()
|
6256 | 6260 | ]
|
6257 |
| - result = pd.concat(results, axis=1, copy=False) |
| 6261 | + result = concat(results, axis=1, copy=False) |
6258 | 6262 | return result
|
6259 | 6263 |
|
6260 | 6264 | # ----------------------------------------------------------------------
|
@@ -6532,10 +6536,8 @@ def replace(
|
6532 | 6536 |
|
6533 | 6537 | if isinstance(to_replace, (tuple, list)):
|
6534 | 6538 | if isinstance(self, ABCDataFrame):
|
6535 |
| - from pandas import Series |
6536 |
| - |
6537 | 6539 | return self.apply(
|
6538 |
| - Series._replace_single, |
| 6540 | + self._constructor_sliced._replace_single, |
6539 | 6541 | args=(to_replace, method, inplace, limit),
|
6540 | 6542 | )
|
6541 | 6543 | self = cast("Series", self)
|
|
0 commit comments