8000 DEPS: Address numpy deprecation of len 1 arrays assignment by mroeschke · Pull Request #52906 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DEPS: Address numpy deprecation of len 1 arrays assignment #52906

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 8 commits into from
Apr 26, 2023
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
Address csv error, undo one fix
  • Loading branch information
mroeschke committed Apr 25, 2023
commit 9e5551e6fbf574d1eef8643deb14755d1281f2a0
2 changes: 1 addition & 1 deletion pandas/_testing/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class for all warnings. To raise multiple types of exceptions,

..warn:: This is *not* thread-safe.
"""
# __tracebackhide__ = True
__tracebackhide__ = True

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter(filter_level)
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,9 +1754,9 @@ def _setitem_with_indexer(self, indexer, value, name: str = "iloc"):
# if not Series (in which case we need to align),
# we can short-circuit
if (
isinstance(value, np.ndarray)
and value.ndim == 1
and len(value) == 1
isinstance(arr, np.ndarray)
and arr.ndim == 1
and len(arr) == 1
):
# NumPy 1.25 deprecation: https://github.com/numpy/numpy/pull/10615
arr = arr[0]
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,9 +1063,6 @@ def setitem(self, indexer, value, using_cow: bool = False) -> Block:
self = self.make_block_same_class(
values.T if values.ndim == 2 else values
)
if isinstance(value, np.ndarray) and value.ndim == 1 and len(value) == 1:
# NumPy 1.25 deprecation: https://github.com/numpy/numpy/pull/10615
casted = casted[0]
values[indexer] = casted
return self

Expand Down
10 changes: 9 additions & 1 deletion pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,12 @@ def _make_date_converter(
if date_parser is not lib.no_default and date_format is not None:
raise TypeError("Cannot use both 'date_parser' and 'date_format'")

def unpack_if_single_element(arg):
# NumPy 1.25 deprecation: https://github.com/numpy/numpy/pull/10615
if isinstance(arg, np.ndarray) and arg.ndim == 1 and len(arg) == 1:
return arg[0]
return arg

def converter(*date_cols, col: Hashable):
if date_parser is lib.no_default:
strs = parsing.concat_date_cols(date_cols)
Expand All @@ -1137,7 +1143,9 @@ def converter(*date_cols, col: Hashable):
else:
try:
result = tools.to_datetime(
date_parser(*date_cols), errors="ignore", cache=cache_dates
date_parser(*(unpack_if_single_element(arg) for arg in date_cols)),
errors="ignore",
cache=cache_dates,
)
if isinstance(result, datetime.datetime):
raise Exception("scalar parser")
Expand Down
0