Skip to content

REF: Use nonzero in place of argwhere #31853

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 1 commit into from
Feb 11, 2020
Merged
Changes from all commits
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
6 changes: 1 addition & 5 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,17 +1671,13 @@ def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFra
continue

if convert_missing: # Replacement follows Stata notation
missing_loc = np.argwhere(missing._ndarray_values)
missing_loc = np.nonzero(missing._ndarray_values)[0]
umissing, umissing_loc = np.unique(series[missing], return_inverse=True)
replacement = Series(series, dtype=np.object)
for j, um in enumerate(umissing):
missing_value = StataMissingValue(um)

loc = missing_loc[umissing_loc == j]
if loc.ndim == 2 and loc.shape[1] == 1:
# GH#31813 avoid trying to set Series values with wrong
# dimension
loc = loc[:, 0]
replacement.iloc[loc] = missing_value
else: # All replacements are identical
dtype = series.dtype
Expand Down