Skip to content
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
11 changes: 7 additions & 4 deletions dataretrieval/nwis.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,14 @@ def format_response(
else:
keys = ["datetime"]

# Index our own frame, never the caller's. The shallow copy shares the
# columns; ``set_index`` without ``inplace`` duplicates them, because
# pandas deep-copies the frame whenever copy-on-write is off.
# Index our own frame, never the caller's. Popping the keys off a shallow
# copy leaves the other columns shared; ``set_index`` copies them when
# copy-on-write is off, and pandas 3.1 deprecates its ``inplace``.
df = df.copy(deep=False)
df.set_index(keys, inplace=True) # noqa: PD002 # our copy, not the caller's
levels = [df.pop(key) for key in keys]
df.index = (
pd.MultiIndex.from_arrays(levels) if len(levels) > 1 else pd.Index(levels[0])
)

# Retag the index alone; ``DataFrame.tz_localize`` relabels the axis by
# duplicating every column whenever copy-on-write is off.
Expand Down
Loading