Skip to content

Commit

Permalink
Fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Sep 29, 2022
1 parent afe9ca5 commit af6056b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ dtype : Type name or dict of column -> type, default ``None``
the default determines the dtype of the columns which are not explicitly
listed.

use_nullable_dtypes: bool = False
use_nullable_dtypes : bool = False
Whether or not to use nullable dtypes as default when reading data. If
set to True, nullable dtypes are used for all dtypes that have a nullable
implementation, even if no nulls are present.
Expand Down
14 changes: 9 additions & 5 deletions pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Hashable,
Iterable,
List,
Literal,
Mapping,
Sequence,
Tuple,
Expand Down Expand Up @@ -716,7 +717,10 @@ def _infer_types(self, values, na_values, cast_type, try_num_bool: bool = True):
np.putmask(values, mask, np.nan)
return values, na_count

use_nullable_dtypes = self.use_nullable_dtypes and cast_type is None
use_nullable_dtypes: Literal[True] | Literal[False] = (
self.use_nullable_dtypes and cast_type is None
)
result: ArrayLike

if try_num_bool and is_object_dtype(values.dtype):
# exclude e.g DatetimeIndex here
Expand Down Expand Up @@ -753,16 +757,16 @@ def _infer_types(self, values, na_values, cast_type, try_num_bool: bool = True):
na_count = parsers.sanitize_objects(values, na_values)

if result.dtype == np.object_ and try_num_bool:
result, mask = libops.maybe_convert_bool(
result, bool_mask = libops.maybe_convert_bool(
np.asarray(values),
true_values=self.true_values,
false_values=self.false_values,
convert_to_masked_nullable=use_nullable_dtypes,
)
if result.dtype == np.bool_ and use_nullable_dtypes:
if mask is None:
mask = np.zeros(result.shape, dtype=np.bool_)
result = BooleanArray(result, mask)
if bool_mask is None:
bool_mask = np.zeros(result.shape, dtype=np.bool_)
result = BooleanArray(result, bool_mask)
elif result.dtype == np.object_ and use_nullable_dtypes:
result = StringDtype().construct_array_type()._from_sequence(values)

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@
.. versionadded:: 1.2
use_nullable_dtypes: bool = False
use_nullable_dtypes : bool = False
Whether or not to use nullable dtypes as default when reading data. If
set to True, nullable dtypes are used for all dtypes that have a nullable
implementation, even if no nulls are present.
Expand Down

0 comments on commit af6056b

Please sign in to comment.