Skip to content

Commit 37d9a17

Browse files
authored
remove circular import (#39152)
1 parent 76701a6 commit 37d9a17

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pandas/core/generic.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
from pandas.core.dtypes.inference import is_hashable
8686
from pandas.core.dtypes.missing import isna, notna
8787

88-
import pandas as pd
8988
from pandas.core import arraylike, indexing, missing, nanops
9089
import pandas.core.algorithms as algos
9190
from pandas.core.arrays import ExtensionArray
@@ -106,6 +105,7 @@
106105
from pandas.core.internals import ArrayManager, BlockManager
107106
from pandas.core.missing import find_valid_index
108107
from pandas.core.ops import align_method_FRAME
108+
from pandas.core.reshape.concat import concat
109109
from pandas.core.shared_docs import _shared_docs
110110
from pandas.core.sorting import get_indexer_indexer
111111
from pandas.core.window import Expanding, ExponentialMovingWindow, Rolling, Window
@@ -5304,7 +5304,11 @@ def sample(
53045304
"when sampling from a Series."
53055305
)
53065306

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")
53085312

53095313
if len(weights) != axis_length:
53105314
raise ValueError(
@@ -5890,7 +5894,7 @@ def astype(
58905894
return self.copy()
58915895

58925896
# GH 19920: retain column metadata after concat
5893-
result = pd.concat(results, axis=1, copy=False)
5897+
result = concat(results, axis=1, copy=False)
58945898
result.columns = self.columns
58955899
return result
58965900

@@ -6254,7 +6258,7 @@ def convert_dtypes(
62546258
)
62556259
for col_name, col in self.items()
62566260
]
6257-
result = pd.concat(results, axis=1, copy=False)
6261+
result = concat(results, axis=1, copy=False)
62586262
return result
62596263

62606264
# ----------------------------------------------------------------------
@@ -6532,10 +6536,8 @@ def replace(
65326536

65336537
if isinstance(to_replace, (tuple, list)):
65346538
if isinstance(self, ABCDataFrame):
6535-
from pandas import Series
6536-
65376539
return self.apply(
6538-
Series._replace_single,
6540+
self._constructor_sliced._replace_single,
65396541
args=(to_replace, method, inplace, limit),
65406542
)
65416543
self = cast("Series", self)

0 commit comments

Comments
 (0)