Skip to content

REF: StringArray._from_sequence, use less memory #35519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ASVs
  • Loading branch information
topper-123 committed Aug 16, 2020
commit 3db2884c9878e3f7e1361a0b664a0b6d497db421
2 changes: 2 additions & 0 deletions asv_bench/benchmarks/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pandas as pd

from .pandas_vb_common import tm


class BooleanArray:
def setup(self):
Expand Down
15 changes: 15 additions & 0 deletions asv_bench/benchmarks/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
from .pandas_vb_common import tm


class Construction:

params = ["str", "string"]
param_names = ["dtype"]

def setup(self):
self.data = tm.rands_array(nchars=10 ** 5, size=10)

def time_construction(self, dtype):
Series(self.data, dtype=dtype)

def peakmem_construction(self, dtype):
Series(self.data, dtype=dtype)


class Methods:
def setup(self):
self.s = Series(tm.makeStringIndex(10 ** 5))
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def astype_intsafe(ndarray[object] arr, new_dtype):
@cython.wraparound(False)
@cython.boundscheck(False)
cpdef ndarray[object] ensure_string_array(
ndarray arr,
arr,
object na_value=np.nan,
bint convert_na_value=True,
bint copy=True,
Expand Down
1 change: 0 additions & 1 deletion pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,6 @@ def construct_1d_ndarray_preserving_na(
"""

if dtype is not None and dtype.kind == "U":
values = np.asarray(values, dtype="object")
subarr = lib.ensure_string_array(values, convert_na_value=False, copy=copy)
else:
subarr = np.array(values, dtype=dtype, copy=copy)
Expand Down