diff --git a/asv_bench/benchmarks/frame_methods.py b/asv_bench/benchmarks/frame_methods.py index 3adb0597cf563..96fe90ce08c5f 100644 --- a/asv_bench/benchmarks/frame_methods.py +++ b/asv_bench/benchmarks/frame_methods.py @@ -512,19 +512,10 @@ def setup(self, axis): self.df_mixed = self.df.copy() self.df_mixed["foo"] = "bar" - self.df.index = MultiIndex.from_arrays([self.df.index, self.df.index]) - self.df.columns = MultiIndex.from_arrays([self.df.columns, self.df.columns]) - self.df_mixed.index = MultiIndex.from_arrays( - [self.df_mixed.index, self.df_mixed.index] - ) - self.df_mixed.columns = MultiIndex.from_arrays( - [self.df_mixed.columns, self.df_mixed.columns] - ) - - def time_count_level_multi(self, axis): + def time_count(self, axis): self.df.count(axis=axis) - def time_count_level_mixed_dtypes_multi(self, axis): + def time_count_mixed_dtypes(self, axis): self.df_mixed.count(axis=axis) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3b2fe1699e996..e3f56fc6421f8 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10991,9 +10991,8 @@ def count(self, axis: Axis = 0, numeric_only: bool = False): Returns ------- - Series or DataFrame + Series For each column/row the number of non-NA/null entries. - If `level` is specified returns a `DataFrame`. See Also -------- @@ -11051,7 +11050,7 @@ def count(self, axis: Axis = 0, numeric_only: bool = False): else: result = notna(frame).sum(axis=axis) - return result.astype("int64").__finalize__(self, method="count") + return result.astype("int64", copy=False).__finalize__(self, method="count") def _reduce( self,