Skip to content

DOC: add note to docstring about dtype keyword when creating Series from abother Series #59300

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

Conversation

taranarmo
Copy link
Contributor

@taranarmo taranarmo commented Jul 23, 2024

When creating Series from another Series dtype keyword is not not used. Add note on dtype keyword to Series and DataFrame constructor. See GH #59060.

@taranarmo taranarmo force-pushed the create-series-from-series-with-dtype-warning branch from 78bc8d4 to 82ca349 Compare July 23, 2024 13:47
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A warning would be too noisy. A note in the docs would be sufficient.

@rhshadrach rhshadrach added Docs Series Series data structure Constructors Series/DataFrame/Index/pd.array Constructors labels Jul 23, 2024
@taranarmo taranarmo force-pushed the create-series-from-series-with-dtype-warning branch from 82ca349 to d478473 Compare July 24, 2024 13:03
When creating Series from another Series `dtype` keyword is ignored.
See GH pandas-dev#59060. Add note to the docstring to underline this behaviour to
Series and DataFrame constructors.
@taranarmo taranarmo force-pushed the create-series-from-series-with-dtype-warning branch from d478473 to 9591092 Compare July 24, 2024 13:18
@taranarmo
Copy link
Contributor Author

Undo the previous changes and add a note to the dtype keyword on pd.Series and pd.DataFrame that says that the keyword is ignored if data is Series and DataFrame correspondingly.

@taranarmo taranarmo requested a review from mroeschke July 24, 2024 13:21
@taranarmo taranarmo changed the title BUG: add warning when creating Series from Series with dtype keyword BUG: add note to docstring about dtype keyword when creating Series from abother Series Jul 24, 2024
Co-authored-by: Matthew Roeschke <[email protected]>
@mroeschke mroeschke added this to the 3.0 milestone Jul 24, 2024
@mroeschke mroeschke merged commit dca602b into pandas-dev:main Jul 24, 2024
42 of 45 checks passed
@mroeschke
Copy link
Member

Thanks @taranarmo

@jorisvandenbossche
Copy link
Member

I was going to comment that I find this a bit surprising behaviour, and so whether we shouldn't rather consider this as a bug instead of documenting it.

But from a quick check, it seems that the dtype argument in fact is not ignored, at least not in all cases (#59060 clearly shows there are also cases where it is indeed ignored):

In [18]: pd.Series(pd.Series([1.0], dtype=float), dtype=int)
Out[18]: 
0    1
dtype: int64

Here it does cast the float series to an int64 dtype, so the dtype keyword was not ignored.

Will also comment on the issue, but so it seems the simple "If data is Series then is ignored." message added in this PR is not fully correct.

@jorisvandenbossche jorisvandenbossche changed the title BUG: add note to docstring about dtype keyword when creating Series from abother Series DOC: add note to docstring about dtype keyword when creating Series from abother Series Jul 26, 2024
@jbrockmendel
Copy link
Member

IIUC I agree with Joris. The solution is not to change the doc, but to make the behavior consistent. The dtype kwarg should never be silently ignored.

@taranarmo taranarmo deleted the create-series-from-series-with-dtype-warning branch May 12, 2025 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Docs Series Series data structure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: dtype keyword in Series constructor ignored for Series input in certain cases
5 participants