Skip to content

Commit

Permalink
ascii3
Browse files Browse the repository at this point in the history
  • Loading branch information
Abby VeCasey authored and Abby VeCasey committed Dec 9, 2024
1 parent 77744aa commit cf90253
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions pandas/core/arrays/_arrow_string_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,28 @@ def _str_isascii(self):
# result = pa.array(pylist, type=pa.bool_())
# return self._convert_bool_result(result)

# def _str_isascii(self):
# if isinstance(self, str):
# result = all(ord(char) < 128 for char in self)
# return self._convert_bool_result(result)
# return None

def _str_isascii(self):
if isinstance(self, str):
result = all(ord(char) < 128 for char in self)
return self._convert_bool_result(result)
return None
# Assuming self._pa_array is a PyArrow array of strings
pylist = []
for s in self._pa_array:
if s is None: # Handle None explicitly
pylist.append(None)
elif isinstance(s, str):
# Check if the string is ASCII using ord() on each character
result = all(ord(char) < 128 for char in s)
pylist.append(result)
else:
pylist.append(None) # If it's not a string, append None

# Convert the result back to a PyArrow array (or pandas series if needed)
result = pa.array(pylist, type=pa.bool_()) # Use boolean type
return self._convert_bool_result(result)


# def _str_isascii(self):
Expand Down

0 comments on commit cf90253

Please sign in to comment.