Skip to content

Commit ecd922b

Browse files
Merge remote-tracking branch 'upstream/main' into bisect
2 parents 568d90a + 7d2f9b8 commit ecd922b

19 files changed

+246
-101
lines changed

doc/source/reference/testing.rst

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Exceptions and warnings
4343
errors.ParserError
4444
errors.ParserWarning
4545
errors.PerformanceWarning
46+
errors.PyperclipException
47+
errors.PyperclipWindowsException
4648
errors.SettingWithCopyError
4749
errors.SettingWithCopyWarning
4850
errors.SpecificationError

doc/source/whatsnew/v1.4.4.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Fixed regressions
2323

2424
Bug fixes
2525
~~~~~~~~~
26-
-
26+
- The :class:`errors.FutureWarning` raised when passing arguments (other than ``filepath_or_buffer``) as positional in :func:`read_csv` is now raised at the correct stacklevel (:issue:`47385`)
2727
-
2828

2929
.. ---------------------------------------------------------------------------

pandas/core/arrays/datetimes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,15 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps):
193193
"""
194194

195195
_typ = "datetimearray"
196-
_scalar_type = Timestamp
197196
_internal_fill_value = np.datetime64("NaT", "ns")
198197
_recognized_scalars = (datetime, np.datetime64)
199198
_is_recognized_dtype = is_datetime64_any_dtype
200199
_infer_matches = ("datetime", "datetime64", "date")
201200

201+
@property
202+
def _scalar_type(self) -> type[Timestamp]:
203+
return Timestamp
204+
202205
# define my properties & methods for delegation
203206
_bool_ops: list[str] = [
204207
"is_month_start",

pandas/core/arrays/interval.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import textwrap
99
from typing import (
1010
TYPE_CHECKING,
11+
Literal,
1112
Sequence,
1213
TypeVar,
1314
Union,
@@ -204,10 +205,13 @@
204205
}
205206
)
206207
class IntervalArray(IntervalMixin, ExtensionArray):
207-
ndim = 1
208208
can_hold_na = True
209209
_na_value = _fill_value = np.nan
210210

211+
@property
212+
def ndim(self) -> Literal[1]:
213+
return 1
214+
211215
# To make mypy recognize the fields
212216
_left: np.ndarray
213217
_right: np.ndarray

pandas/core/arrays/period.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,15 @@ class PeriodArray(dtl.DatelikeOps, libperiod.PeriodMixin):
167167
# array priority higher than numpy scalars
168168
__array_priority__ = 1000
169169
_typ = "periodarray" # ABCPeriodArray
170-
_scalar_type = Period
171170
_internal_fill_value = np.int64(iNaT)
172171
_recognized_scalars = (Period,)
173172
_is_recognized_dtype = is_period_dtype
174173
_infer_matches = ("period",)
175174

175+
@property
176+
def _scalar_type(self) -> type[Period]:
177+
return Period
178+
176179
# Names others delegate to us
177180
_other_ops: list[str] = []
178181
_bool_ops: list[str] = ["is_leap_year"]

pandas/core/arrays/timedeltas.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,15 @@ class TimedeltaArray(dtl.TimelikeOps):
119119
"""
120120

121121
_typ = "timedeltaarray"
122-
_scalar_type = Timedelta
123122
_internal_fill_value = np.timedelta64("NaT", "ns")
124123
_recognized_scalars = (timedelta, np.timedelta64, Tick)
125124
_is_recognized_dtype = is_timedelta64_dtype
126125
_infer_matches = ("timedelta", "timedelta64")
127126

127+
@property
128+
def _scalar_type(self) -> type[Timedelta]:
129+
return Timedelta
130+
128131
__array_priority__ = 1000
129132
# define my properties & methods for delegation
130133
_other_ops: list[str] = []

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def __len__(self) -> int:
318318
raise AbstractMethodError(self)
319319

320320
@property
321-
def ndim(self) -> int:
321+
def ndim(self) -> Literal[1]:
322322
"""
323323
Number of dimensions of the underlying data, by definition 1.
324324
"""

pandas/core/internals/array_manager.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Any,
99
Callable,
1010
Hashable,
11+
Literal,
1112
TypeVar,
1213
)
1314

@@ -704,7 +705,9 @@ def _equal_values(self, other) -> bool:
704705

705706

706707
class ArrayManager(BaseArrayManager):
707-
ndim = 2
708+
@property
709+
def ndim(self) -> Literal[2]:
710+
return 2
708711

709712
def __init__(
710713
self,
@@ -1191,7 +1194,9 @@ class SingleArrayManager(BaseArrayManager, SingleDataManager):
11911194
arrays: list[np.ndarray | ExtensionArray]
11921195
_axes: list[Index]
11931196

1194-
ndim = 1
1197+
@property
1198+
def ndim(self) -> Literal[1]:
1199+
return 1
11951200

11961201
def __init__(
11971202
self,

pandas/core/internals/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
from typing import (
8+
Literal,
89
TypeVar,
910
final,
1011
)
@@ -155,7 +156,9 @@ def _consolidate_inplace(self) -> None:
155156

156157

157158
class SingleDataManager(DataManager):
158-
ndim = 1
159+
@property
160+
def ndim(self) -> Literal[1]:
161+
return 1
159162

160163
@final
161164
@property

pandas/core/internals/managers.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Any,
66
Callable,
77
Hashable,
8+
Literal,
89
Sequence,
910
TypeVar,
1011
cast,
@@ -142,7 +143,10 @@ class BaseBlockManager(DataManager):
142143
blocks: tuple[Block, ...]
143144
axes: list[Index]
144145

145-
ndim: int
146+
@property
147+
def ndim(self) -> int:
148+
raise NotImplementedError
149+
146150
_known_consolidated: bool
147151
_is_consolidated: bool
148152

@@ -1678,7 +1682,10 @@ def _consolidate_inplace(self) -> None:
16781682
class SingleBlockManager(BaseBlockManager, SingleDataManager):
16791683
"""manage a single block with"""
16801684

1681-
ndim = 1
1685+
@property
1686+
def ndim(self) -> Literal[1]:
1687+
return 1
1688+
16821689
_is_consolidated = True
16831690
_known_consolidated = True
16841691
__slots__ = ()

pandas/errors/__init__.py

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
from __future__ import annotations
55

6+
import ctypes
7+
68
from pandas._config.config import OptionError # noqa:F401
79

810
from pandas._libs.tslibs import ( # noqa:F401
@@ -374,3 +376,22 @@ class IndexingError(Exception):
374376
>>> s.loc["a", "c", "d"] # doctest: +SKIP
375377
... # IndexingError: Too many indexers
376378
"""
379+
380+
381+
class PyperclipException(RuntimeError):
382+
"""
383+
Exception is raised when trying to use methods like to_clipboard() and
384+
read_clipboard() on an unsupported OS/platform.
385+
"""
386+
387+
388+
class PyperclipWindowsException(PyperclipException):
389+
"""
390+
Exception is raised when pandas is unable to get access to the clipboard handle
391+
due to some other window process is accessing it.
392+
"""
393+
394+
def __init__(self, message: str) -> None:
395+
# attr only exists on Windows, so typing fails on other platforms
396+
message += f" ({ctypes.WinError()})" # type: ignore[attr-defined]
397+
super().__init__(message)

pandas/io/clipboard/__init__.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
import time
5959
import warnings
6060

61+
from pandas.errors import (
62+
PyperclipException,
63+
PyperclipWindowsException,
64+
)
65+
6166
# `import PyQt4` sys.exit()s if DISPLAY is not in the environment.
6267
# Thus, we need to detect the presence of $DISPLAY manually
6368
# and not load PyQt4 if it is absent.
@@ -87,18 +92,6 @@ def _executable_exists(name):
8792
)
8893

8994

90-
# Exceptions
91-
class PyperclipException(RuntimeError):
92-
pass
93-
94-
95-
class PyperclipWindowsException(PyperclipException):
96-
def __init__(self, message) -> None:
97-
# attr only exists on Windows, so typing fails on other platforms
98-
message += f" ({ctypes.WinError()})" # type: ignore[attr-defined]
99-
super().__init__(message)
100-
101-
10295
def _stringifyText(text) -> str:
10396
acceptedTypes = (str, int, float, bool)
10497
if not isinstance(text, acceptedTypes):

pandas/io/parsers/readers.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,7 @@ def read_csv(
829829
...
830830

831831

832-
@deprecate_nonkeyword_arguments(
833-
version=None, allowed_args=["filepath_or_buffer"], stacklevel=3
834-
)
832+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
835833
@Appender(
836834
_doc_read_csv_and_table.format(
837835
func_name="read_csv",

0 commit comments

Comments
 (0)