Repository: pandas-dev/pandas-stubs (language: python)

Issue:
python 3.12 and pyright 1.1.334 error:  Method "fromtimestamp" overrides class "datetime" in an incompatible manner
**Describe the bug**
I'm Follwing the setup.md to set up an development envirment. When I  execute  `poe test_all` .Pyright test cannot be finished and prints this error message.

**To Reproduce**
1. Provide a minimal runnable `pandas` example that is not properly checked by the stubs.
unit test in `tests/`
3. Indicate which type checker you are using (`mypy` or  `pyright`).
pyright
5. Show the error message received from that type checker while checking your example.
```
prompt> poe test_all                                                                         (pandas_stubs_test) 
Poe => test_all

===========================================
Beginning: 'Run mypy on 'tests' (using the local stubs) and on the local stubs'
===========================================

Success: no issues found in 224 source files

===========================================
End: 'Run mypy on 'tests' (using the local stubs) and on the local stubs', runtime: 27.658 seconds.
===========================================


===========================================
Beginning: 'Run pyright on 'tests' (using the local stubs) and on the local stubs'
===========================================

/pathto/pandas_stubs_test/pandas_stubs_v2/pandas-stubs/_libs/tslibs/timestamps.pyi
  /pathto/pandas_stubs_test/pandas_stubs_v2/pandas-stubs/_libs/tslibs/timestamps.pyi:103:9 - error: Method "fromtimestamp" overrides class "datetime" in an incompatible manner
    Parameter 2 name mismatch: base parameter is named "timestamp", override parameter is named "t" (reportIncompatibleMethodOverride)
1 error, 0 warnings, 0 informations 

===========================================
Step: 'Run pyright on 'tests' (using the local stubs) and on the local stubs' failed!
===========================================
```



 - OS: archlinux
 - OS Version `kernel version: 6.5.8`
 - python version `3.12.0`
 - version of type checker `pyright 1.1.334`
 - version of installed `pandas-stubs` `2.1.1.230928`


**Additional context**
I didn't modify anything in this project.



Discussion / hints:
I can't reproduce this.

This may be an issue in that you're using python 3.12.  Can you try python 3.9 ?

Alternatively, try modifying `pyproject.toml` to use pyright 1.1.333 and do `poetry update` and see if that makes it go away, in which case the issue may be something to do with the pyright 1.1.334 and python 3.12 combination.



> I can't reproduce this.
> 
> This may be an issue in that you're using python 3.12. Can you try python 3.9 ?
> 
> Alternatively, try modifying `pyproject.toml` to use pyright 1.1.333 and do `poetry update` and see if that makes it go away, in which case the issue may be something to do with the pyright 1.1.334 and python 3.12 combination.

Yes, there is not any issue in python 3.9 environment.Here are full logs,maybe useful
_/home/user/py_code/pandas_stubs_test/pandas_stubs_v2 is the root dir of this project ._
**python 3.12.0+pyright v1.1.333,same error**
```
prompt> poetry run poe test_all                               (pandas_stubs_test) 
Poe => test_all

===========================================
Beginning: 'Run mypy on 'tests' (using the local stubs) and on the local stubs'
===========================================

Success: no issues found in 224 source files

===========================================
End: 'Run mypy on 'tests' (using the local stubs) and on the local stubs', runtime: 27.663 seconds.
===========================================


===========================================
Beginning: 'Run pyright on 'tests' (using the local stubs) and on the local stubs'
===========================================

WARNING: there is a new pyright version available (v1.1.333 -> v1.1.334).
Please install the new version or set PYRIGHT_PYTHON_FORCE_VERSION to `latest`

/home/user/py_code/pandas_stubs_test/pandas_stubs_v2/pandas-stubs/_libs/tslibs/timestamps.pyi
  /home/user/py_code/pandas_stubs_test/pandas_stubs_v2/pandas-stubs/_libs/tslibs/timestamps.pyi:103:9 - error: Method "fromtimestamp" overrides class "datetime" in an incompatible manner
    Parameter 2 name mismatch: base parameter is named "timestamp", override parameter is named "t" (reportIncompatibleMethodOverride)
1 error, 0 warnings, 0 informations 

===========================================
Step: 'Run pyright on 'tests' (using the local stubs) and on the local stubs' failed!
===========================================
```

**python 3.9.18+pyright 1.1.334**
```
prompt> poetry run poe test_all                               (pandas_stubs_3.9) 
Poe => test_all

===========================================
Beginning: 'Run mypy on 'tests' (using the local stubs) and on the local stubs'
===========================================

Success: no issues found in 224 source files

===========================================
End: 'Run mypy on 'tests' (using the local stubs) and on the local stubs', runtime: 25.405 seconds.
===========================================


===========================================
Beginning: 'Run pyright on 'tests' (using the local stubs) and on the local stubs'
===========================================

0 errors, 0 warnings, 0 informations 

===========================================
End: 'Run pyright on 'tests' (using the local stubs) and on the local stubs', runtime: 17.495 seconds.
===========================================


===========================================
Beginning: 'Run pytest'
===========================================

==================================================== test session starts =====================================================
platform linux -- Python 3.9.18, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/user/py_code/pandas_stubs_test/pandas_stubs_v2
collected 992 items                                                                                                          

tests/test_api_types.py ...........................................                                                    [  4%]
tests/test_config.py ...                                                                                               [  4%]
tests/test_dtypes.py ..........                                                                                        [  5%]
tests/test_errors.py .........................s..........                                                              [  9%]
tests/test_extension.py ..                                                                                             [  9%]
tests/test_frame.py .................................................................................s................ [ 19%]
........................................................................                                               [ 26%]
tests/test_holidays.py .                                                                                               [ 26%]
tests/test_indexes.py ...............................                                                                  [ 29%]
tests/test_interval.py .....                                                                                           [ 30%]
tests/test_interval_index.py ......                                                                                    [ 30%]
tests/test_io.py ................ss...............................................s...                                 [ 37%]
tests/test_merge.py .                                                                                                  [ 38%]
tests/test_pandas.py ............................                                                                      [ 40%]
tests/test_plotting.py ........................                                                                        [ 43%]
tests/test_resampler.py ...............................                                                                [ 46%]
tests/test_scalars.py .............................                                                                    [ 49%]
tests/test_series.py ................................................................................................. [ 59%]
............................................................sss....................................................... [ 70%]
...................................................................................................................... [ 82%]
.......................................................................                                                [ 90%]
tests/test_styler.py ...........................                                                                       [ 92%]
tests/test_testing.py ...                                                                                              [ 93%]
tests/test_timefuncs.py .............................................                                                  [ 97%]
tests/test_utility.py ....                                                                                             [ 97%]
tests/test_windowing.py ....................                                                                           [100%]

============================================== 984 passed, 8 skipped in 16.05s ===============================================

===========================================
End: 'Run pytest', runtime: 16.561 seconds.
===========================================


===========================================
Beginning: 'Run pre-commit'
===========================================

black....................................................................Passed
- hook id: black
- duration: 0.17s

All done! ✨ 🍰 ✨
230 files left unchanged.

isort....................................................................Passed
- hook id: isort
- duration: 0.43s
ruff.....................................................................Passed
- hook id: ruff
- duration: 0.06s
codespell................................................................Passed
- hook id: codespell
- duration: 0.22s

===========================================
End: 'Run pre-commit', runtime: 1.078 seconds.
===========================================


===========================================
Beginning: 'Build pandas-stubs'
===========================================

Building pandas-stubs (2.1.1.230928)
  - Building wheel
  - Built pandas_stubs-2.1.1.230928-py3-none-any.whl

===========================================
End: 'Build pandas-stubs', runtime: 0.996 seconds.
===========================================


===========================================
Beginning: 'Install pandas-stubs'
===========================================

Processing ./dist/pandas_stubs-2.1.1.230928-py3-none-any.whl
Collecting numpy>=1.26.0 (from pandas-stubs==2.1.1.230928)
  Using cached numpy-1.26.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
Collecting types-pytz>=2022.1.1 (from pandas-stubs==2.1.1.230928)
  Using cached types_pytz-2023.3.1.1-py3-none-any.whl.metadata (1.3 kB)
Using cached numpy-1.26.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
Using cached types_pytz-2023.3.1.1-py3-none-any.whl (4.9 kB)
Installing collected packages: types-pytz, numpy, pandas-stubs
  Attempting uninstall: types-pytz
    Found existing installation: types-pytz 2023.3.1.1
    Uninstalling types-pytz-2023.3.1.1:
      Successfully uninstalled types-pytz-2023.3.1.1
  Attempting uninstall: numpy
    Found existing installation: numpy 1.26.1
    Uninstalling numpy-1.26.1:
      Successfully uninstalled numpy-1.26.1
Successfully installed numpy-1.26.1 pandas-stubs-2.1.1.230928 types-pytz-2023.3.1.1

===========================================
End: 'Install pandas-stubs', runtime: 2.857 seconds.
===========================================


===========================================
Beginning: 'Rename local stubs'
===========================================


===========================================
End: 'Rename local stubs', runtime: 0.000 seconds.
===========================================


===========================================
Beginning: 'Run mypy on 'tests' using the installed stubs'
===========================================

Success: no issues found in 26 source files

===========================================
End: 'Run mypy on 'tests' using the installed stubs', runtime: 24.801 seconds.
===========================================


===========================================
Beginning: 'Run pyright on 'tests' using the installed stubs'
===========================================

File or directory "/home/user/py_code/pandas_stubs_test/pandas_stubs_v2/pandas-stubs" does not exist.
0 errors, 0 warnings, 0 informations 

===========================================
End: 'Run pyright on 'tests' using the installed stubs', runtime: 16.167 seconds.
===========================================


===========================================
Undoing: Rename local stubs
===========================================


===========================================
Undoing: Install pandas-stubs
===========================================

Found existing installation: pandas-stubs 2.1.1.230928
Uninstalling pandas-stubs-2.1.1.230928:
  Successfully uninstalled pandas-stubs-2.1.1.230928
```

BTW, the logs of python 3.9 envrioment containes `File or directory "/home/user/py_code/pandas_stubs_test/pandas_stubs_v2/pandas-stubs" does not exist.`. Is thie serious?
Thanks for the tests.

It sounds like with python 3.12, we have a failure with the latest version of pyright and the typeshed stubs.  

I don't think the error you received in the python 3.9 environment is an issue.

I've updated the title of the issue since it will allow us to focus on what is wrong.


Fix patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d3559f982..35165128e 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -3,7 +3,7 @@ ci:
     autofix_prs: false
 repos:
 -   repo: https://github.com/python/black
-    rev: 23.12.0
+    rev: 23.12.1
     hooks:
     -   id: black
 -   repo: https://github.com/PyCQA/isort
@@ -11,7 +11,7 @@ repos:
     hooks:
     -   id: isort
 -   repo: https://github.com/astral-sh/ruff-pre-commit
-    rev: v0.1.8
+    rev: v0.1.9
     hooks:
     -   id: ruff
         args: [
diff --git a/pandas-stubs/_libs/tslibs/timestamps.pyi b/pandas-stubs/_libs/tslibs/timestamps.pyi
index dbf151c7b..a8bf36b87 100644
--- a/pandas-stubs/_libs/tslibs/timestamps.pyi
+++ b/pandas-stubs/_libs/tslibs/timestamps.pyi
@@ -6,6 +6,7 @@ from datetime import (
     timedelta,
     tzinfo as _tzinfo,
 )
+import sys
 from time import struct_time
 from typing import (
     ClassVar,
@@ -99,8 +100,16 @@ class Timestamp(datetime):
     def tz(self) -> _tzinfo | None: ...
     @property
     def fold(self) -> int: ...
-    @classmethod
-    def fromtimestamp(cls, t: float, tz: _tzinfo | str | None = ...) -> Self: ...
+
+    if sys.version_info < (3, 12):
+        @classmethod
+        def fromtimestamp(cls, t: float, tz: _tzinfo | str | None = ...) -> Self: ...
+    else:
+        @classmethod
+        def fromtimestamp(  # pyright: ignore[reportIncompatibleMethodOverride]
+            cls, t: float, tz: _tzinfo | str | None = ...
+        ) -> Self: ...
+
     @classmethod
     def utcfromtimestamp(cls, ts: float) -> Self: ...
     @classmethod
diff --git a/pyproject.toml b/pyproject.toml
index a29d4ab56..8a2693e62 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -35,7 +35,7 @@ types-pytz = ">= 2022.1.1"
 numpy = { version = ">=1.26.0", python = "<3.13" }
 
 [tool.poetry.group.dev.dependencies]
-mypy = "1.7.1"
+mypy = "1.8.0"
 pandas = "2.1.4"
 pyarrow = ">=10.0.1"
 pytest = ">=7.1.2"
@@ -62,7 +62,6 @@ jinja2 = ">=3.1"
 scipy = { version = ">=1.9.1", python = "<3.13" }
 SQLAlchemy = ">=2.0.12"
 types-python-dateutil = ">=2.8.19"
-numexpr = "<2.8.5"  # https://github.com/pandas-dev/pandas/issues/54449
 beautifulsoup4 = ">=4.12.2"
 html5lib = ">=1.1"
 
@@ -199,6 +198,14 @@ useLibraryCodeForTypes = false
 [tool.codespell]
 ignore-words-list = "indext, mose, sav, ser"
 
+[tool.pytest.ini_options]
+filterwarnings = [
+  # treat warnings as errors
+  "error",
+  # until there is a new dateutil release: github.com/dateutil/dateutil/pull/1285
+  "ignore:datetime.datetime.utc:DeprecationWarning",
+]
+
 # Next line needed to avoid poetry complaint
 [tool.setuptools_scm]
 


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 740540c08..b233de81b 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -18,7 +18,7 @@ jobs:
       fail-fast: false
       matrix:
         os: [ubuntu-latest, windows-latest, macos-latest]
-        python-version: ['3.9', '3.10', '3.11']
+        python-version: ['3.9', '3.10', '3.11', '3.12']
 
     steps:
     - uses: actions/checkout@v3
diff --git a/scripts/test/run.py b/scripts/test/run.py
index e08b41a14..c30395da9 100644
--- a/scripts/test/run.py
+++ b/scripts/test/run.py
@@ -15,8 +15,8 @@ def pyright_src():
     subprocess.run(cmd, check=True)
 
 
-def pytest(flags: tuple[str, ...] = ("-Werror",)):
-    cmd = ["pytest", "--cache-clear", *flags]
+def pytest():
+    cmd = ["pytest", "--cache-clear"]
     subprocess.run(cmd, check=True)
 
 
diff --git a/tests/test_frame.py b/tests/test_frame.py
index bdd9bf491..e3875432f 100644
--- a/tests/test_frame.py
+++ b/tests/test_frame.py
@@ -1699,31 +1699,43 @@ class ReadCsvKwargs(TypedDict):
             pd.DataFrame,
         )
         parse_dates_2 = {"combined_date": ["Year", "Month", "Day"]}
-        check(
-            assert_type(pd.read_csv(path, parse_dates=parse_dates_2), pd.DataFrame),
-            pd.DataFrame,
-        )
+        with pytest_warns_bounded(
+            FutureWarning, "Support for nested sequences", lower="2.1.99"
+        ):
+            check(
+                assert_type(pd.read_csv(path, parse_dates=parse_dates_2), pd.DataFrame),
+                pd.DataFrame,
+            )
         parse_dates_3 = {"combined_date": [1, 2, 3]}
-        check(
-            assert_type(pd.read_csv(path, parse_dates=parse_dates_3), pd.DataFrame),
-            pd.DataFrame,
-        )
+        with pytest_warns_bounded(
+            FutureWarning, "Support for nested sequences", lower="2.1.99"
+        ):
+            check(
+                assert_type(pd.read_csv(path, parse_dates=parse_dates_3), pd.DataFrame),
+                pd.DataFrame,
+            )
         # MyPy calls this Dict[str, object] by default which necessitates the explicit annotation (Pyright does not)
         parse_dates_4: dict[str, list[str | int]] = {"combined_date": [1, "Month", 3]}
-        check(
-            assert_type(pd.read_csv(path, parse_dates=parse_dates_4), pd.DataFrame),
-            pd.DataFrame,
-        )
+        with pytest_warns_bounded(
+            FutureWarning, "Support for nested sequences", lower="2.1.99"
+        ):
+            check(
+                assert_type(pd.read_csv(path, parse_dates=parse_dates_4), pd.DataFrame),
+                pd.DataFrame,
+            )
         parse_dates_5 = [0]
         check(
             assert_type(pd.read_csv(path, parse_dates=parse_dates_5), pd.DataFrame),
             pd.DataFrame,
         )
         parse_dates_6 = [[1, 2, 3]]
-        check(
-            assert_type(pd.read_csv(path, parse_dates=parse_dates_6), pd.DataFrame),
-            pd.DataFrame,
-        )
+        with pytest_warns_bounded(
+            FutureWarning, "Support for nested sequences", lower="2.1.99"
+        ):
+            check(
+                assert_type(pd.read_csv(path, parse_dates=parse_dates_6), pd.DataFrame),
+                pd.DataFrame,
+            )
 
 
 def test_groupby_series_methods() -> None:
diff --git a/tests/test_utility.py b/tests/test_utility.py
index 9a27f822c..70ae19034 100644
--- a/tests/test_utility.py
+++ b/tests/test_utility.py
@@ -1,12 +1,21 @@
+import platform
+
 import pandas as pd
-import pytest
 from typing_extensions import assert_type
 
-from tests import check
+from tests import (
+    check,
+    pytest_warns_bounded,
+)
 
 
 def test_show_version():
-    with pytest.warns(UserWarning, match="Setuptools is replacing distutils"):
+    with pytest_warns_bounded(
+        UserWarning,
+        match="Setuptools is replacing distutils",
+        upper="3.11.99",
+        version_str=platform.python_version(),
+    ):
         check(assert_type(pd.show_versions(True), None), type(None))
         check(assert_type(pd.show_versions(False), None), type(None))