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

Issue:
Series constructor does not accept TypedDict
**Describe the bug**
When creating a series from a TypedDict, Pyright reports

`No overloads for "__new__" match the provided arguments. Argument of type (TypedDict) cannot be assigned to parameter "data" of type "Scalar | _ListLike[Unknown] | dict[HashableT1@__new__, Any] | BaseGroupBy[Unknown] | NaTType | NAType | None" in function "__new__"`

**To Reproduce**

```
from typing import TypedDict
import pandas as pd
class MyDict(TypedDict):
    a: str
    b: str

my_dict = MyDict(a="", b="")
pd.Series(my_dict)
```
Pyright yields 

```
error: No overloads for "__new__" match the provided arguments (reportCallIssue)
error: Argument of type "MyDict" cannot be assigned to parameter "data" of type "Scalar | _ListLike[Unknown] | dict[HashableT1@__new__, Any] | BaseGroupBy[Unknown] | NaTType | NAType | None" in function "__new__"
    Type "MyDict" is incompatible with type "Scalar | _ListLike[Unknown] | dict[HashableT1@__new__, Any] | BaseGroupBy[Unknown] | NaTType | NAType | None"
      "MyDict" is incompatible with "ExtensionArray"
      "MyDict" is incompatible with "NAType"
      "MyDict" is incompatible with "NaTType"
      "MyDict" is incompatible with "Timedelta"
      "MyDict" is incompatible with "Timestamp"
      "MyDict" is incompatible with "bool"
      "MyDict" is incompatible with "bytes"
    ... (reportArgumentType)
```

**Please complete the following information:**
 - OS: Linux
 - OS Version: 22
 - python version: Python 3.12.4
 - version of type checker: Pyright 1.1.374
 - version of installed `pandas-stubs`: 2.2.2.240603


**Additional context**
Seems like `TypedDict` is incompatible with `dict`, but I don't see why it matters in this specific example. Changing overload 8 (series.pyi(332, 9))

```
@overload
    def __new__(
        cls,
        data: (
            Scalar
            | _ListLike
            | dict[HashableT1, Any]
            | BaseGroupBy
            | NaTType
            | NAType
            | None
        ) = ...,
        index: Axes | None = ...,
        *,
        dtype: Dtype = ...,
        name: Hashable = ...,
        copy: bool = ...,
    ) -> Series: ...
```
to
```
@overload
    def __new__(
        cls,
        data: (
            Scalar
            | _ListLike
            | Mapping[HashableT1, Any]
            | BaseGroupBy
            | NaTType
            | NAType
            | None
        ) = ...,
        index: Axes | None = ...,
        *,
        dtype: Dtype = ...,
        name: Hashable = ...,
        copy: bool = ...,
    ) -> Series: ...
```
fixes this specific example but I don't know if it breaks something elsewhere.


Discussion / hints:
I think that if you changed all the `Series.__new__()` overloads to use `Mapping` instead of `dict`, it would work and handle your use case.

PR with tests welcome.


Fix patch:
diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi
index 24bac1a1..9218b674 100644
--- a/pandas-stubs/core/series.pyi
+++ b/pandas-stubs/core/series.pyi
@@ -334,7 +334,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
         data: (
             Scalar
             | _ListLike
-            | dict[HashableT1, Any]
+            | Mapping[HashableT1, Any]
             | BaseGroupBy
             | NaTType
             | NAType


Test patch:
diff --git a/tests/test_frame.py b/tests/test_frame.py
index 3e09e7b3..64198952 100644
--- a/tests/test_frame.py
+++ b/tests/test_frame.py
@@ -3490,3 +3490,15 @@ def test_info() -> None:
     check(assert_type(df.info(show_counts=True), None), type(None))
     check(assert_type(df.info(show_counts=False), None), type(None))
     check(assert_type(df.info(show_counts=None), None), type(None))
+
+
+def test_series_typed_dict() -> None:
+    """Test that no error is raised when constructing a series from a typed dict."""
+
+    class MyDict(TypedDict):
+        a: str
+        b: str
+
+    my_dict = MyDict(a="", b="")
+    sr = pd.Series(my_dict)
+    check(assert_type(sr, pd.Series), pd.Series)