Skip to content

BUG: Raise clear error when assign is used with non-string column keys #61297

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

Closed
wants to merge 174 commits into from

Conversation

AnushaUKumar
Copy link

What does this PR do?

Fixes confusing behavior when .assign() is used with non-string keys like tuples. Python raises a generic TypeError: keywords must be strings, which confuses users.

This PR adds a more helpful message:

assign() only supports string column names. Use df[('C', 'one')] = ... to assign non-string column names like tuples.

Why?

This improves the developer experience and avoids unnecessary debugging time.

How was this fixed?

  • Added __kwargs_dict__ as a keyword-only argument for testing with tuple keys
  • Added validation in assign() for string-only keys
  • Updated existing test for compatibility
  • Added new test: test_assign_with_tuple_column_key_raises_typeerror

Test added

test_assign_with_tuple_column_key_raises_typeerror

meeseeksmachine and others added 30 commits August 12, 2023 21:55
…ce in maybe_convert_objects) (pandas-dev#54512)

Backport PR pandas-dev#54498: Speed up string inference in maybe_convert_objects

Co-authored-by: Patrick Hoefler <[email protected]>
…upby.rolling.corr) (pandas-dev#54513)

Backport PR pandas-dev#54504: Move Unit Tests for groupby.rolling.corr

Co-authored-by: omar-elbaz <[email protected]>
…ons with EA dtypes) (pandas-dev#54514)

Backport PR pandas-dev#54509: PERF: Dataframe reductions with EA dtypes

Co-authored-by: Luke Manley <[email protected]>
…y(duration) workarounds for pyarrow versions >= 11.0) (pandas-dev#54524)

Backport PR pandas-dev#54515: ENH: ArrowExtensionArray(duration) workarounds for pyarrow versions >= 11.0

Co-authored-by: Luke Manley <[email protected]>
Co-authored-by: Patrick Hoefler <[email protected]>
… with EA dtypes) (pandas-dev#54528)

Backport PR pandas-dev#54341: PERF: axis=1 reductions with EA dtypes

Co-authored-by: Luke Manley <[email protected]>
…ect into a variable) (pandas-dev#54538)

Backport PR pandas-dev#54536: REF: Move checks to object into a variable

Co-authored-by: Patrick Hoefler <[email protected]>
…can be shared with new string dtype) (pandas-dev#54539)

Backport PR pandas-dev#54534: REF: Move methods that can be shared with new string dtype

Co-authored-by: Patrick Hoefler <[email protected]>
…rrow check for string tests) (pandas-dev#54559)

Backport PR pandas-dev#54537: REF: Refactor using_pyarrow check for string tests

Co-authored-by: Patrick Hoefler <[email protected]>
…from 2.14.1 to 2.15.0) (pandas-dev#54558)

Backport PR pandas-dev#54541: Bump pypa/cibuildwheel from 2.14.1 to 2.15.0

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…ependencies list) (pandas-dev#54562)

Backport PR pandas-dev#54493: DOC: updated required dependencies list

Co-authored-by: Rajat Subhra Mukherjee <[email protected]>
…om `numpy` namespace refactor Part 3) (pandas-dev#54583)

Backport PR pandas-dev#54579: ENH: Reflect changes from `numpy` namespace refactor Part 3

Co-authored-by: Mateusz Sokół <[email protected]>
…inements) (pandas-dev#54588)

Backport PR pandas-dev#54545: DOC: whatsnew 2.1.0 refinements

Co-authored-by: Richard Shadrach <[email protected]>
…string storage checks with variable) (pandas-dev#54594)

Backport PR pandas-dev#54535: REF: Replace "pyarrow" string storage checks with variable

Co-authored-by: Patrick Hoefler <[email protected]>
…cumprod support for arrow dtypes) (pandas-dev#54603)

Backport PR pandas-dev#54574: ENH: add cummax/cummin/cumprod support for arrow dtypes

Co-authored-by: Luke Manley <[email protected]>
…uctions in the README) (pandas-dev#54619)

Backport PR pandas-dev#54615: DOC: Update build instructions in the README

Co-authored-by: Thomas Li <[email protected]>
… Dev tests) (pandas-dev#54614)

Backport PR pandas-dev#54587: CI: Enable MacOS Python Dev tests

Co-authored-by: Matthew Roeschke <[email protected]>
…n of na value) (pandas-dev#54658)

Backport PR pandas-dev#54586: REF: Refactor conversion of na value

Co-authored-by: Patrick Hoefler <[email protected]>
…py and brotli as optional dependencies (no longer used)) (pandas-dev#54637)

Backport PR pandas-dev#54633: DEP: remove python-snappy and brotli as optional dependencies (no longer used)

Co-authored-by: Joris Van den Bossche <[email protected]>
…rong axis) (pandas-dev#54669)

Backport PR pandas-dev#54641: BUG: getitem indexing wrong axis

Co-authored-by: Patrick Hoefler <[email protected]>
… with numpy strings with arrow string option) (pandas-dev#54672)

Backport PR pandas-dev#54496: Fix inference for fixed with numpy strings with arrow string option

Co-authored-by: Patrick Hoefler <[email protected]>
…lid PyArrow duration conversion) (pandas-dev#54688)

Backport PR pandas-dev#54678: COMPAT: Workaround invalid PyArrow duration conversion

Co-authored-by: Matthew Roeschke <[email protected]>
…row implementation for merge) (pandas-dev#54689)

Backport PR pandas-dev#54510: Speed up StringDtype arrow implementation for merge

Co-authored-by: Patrick Hoefler <[email protected]>
…twise ops in ArrowExtensionArray) (pandas-dev#54691)

Backport PR pandas-dev#54685: ENH: support integer bitwise ops in ArrowExtensionArray

Co-authored-by: Luke Manley <[email protected]>
…ising for boolean arrow dtype with missing values) (pandas-dev#54692)

Backport PR pandas-dev#54670: BUG: drop_duplicates raising for boolean arrow dtype with missing values

Co-authored-by: Patrick Hoefler <[email protected]>
…all with float, timedelta64 dtypes) (pandas-dev#54693)

Backport PR pandas-dev#54566: ENH: support Index.any/all with float, timedelta64 dtypes

Co-authored-by: jbrockmendel <[email protected]>
… function calls) (pandas-dev#54697)

Backport PR pandas-dev#54694: MAINT: Remove `np.in1d` function calls

Co-authored-by: Mateusz Sokół <[email protected]>
…ing timezone series) (pandas-dev#54698)

Backport PR pandas-dev#54625: BUG: Fix error in printing timezone series

Co-authored-by: Adrian D'Alessandro <[email protected]>
…t] for EA dtypes) (pandas-dev#54700)

Backport PR pandas-dev#54508: PERF: DataFrame.iloc[int] for EA dtypes

Co-authored-by: Luke Manley <[email protected]>
meeseeksmachine and others added 24 commits October 25, 2023 16:22
…ot supporting numba raising TypeError when the…) (pandas-dev#55686)

Backport PR pandas-dev#55586: REGR: Groupby methods not supporting numba raising TypeError when the…

Co-authored-by: Thomas Li <[email protected]>
… incorrect values when ts index is not nano seconds) (pandas-dev#55697)

Backport PR pandas-dev#55173: BUG: .rolling() returns incorrect values when ts index is not nano seconds

Co-authored-by: Hadi Abdi Khojasteh <[email protected]>
…l_method` … (pandas-dev#55701)

Backport PR pandas-dev#55527: BUG fix deprecation of `limit` and `fill_method` in `pct_change`

Co-authored-by: Yao Xiao <[email protected]>
… datetimes with sqlite type detection) (pandas-dev#55702)

REGR: fix roundtripping datetimes with sqlite type detection (pandas-dev#55690)

(cherry picked from commit aeb3644)
…tor_from_mgr to pass manager object to constructor) (pandas-dev#55704)

Backport PR pandas-dev#54922: REGR: Restore _constructor_from_mgr to pass manager object to constructor
…with column of large strings (avoid overflow from concat)) (pandas-dev#55706)

Backport PR pandas-dev#55691: REGR: fix read_parquet with column of large strings (avoid overflow from concat)

Co-authored-by: Joris Van den Bossche <[email protected]>
….1.3) (pandas-dev#55723)

Backport PR pandas-dev#55722: DOC: Add whatsnew for 2.1.3

Co-authored-by: Joris Van den Bossche <[email protected]>
…for scalar inference for NEP 50) (pandas-dev#55716)

Backport PR pandas-dev#55707: REF: Avoid np.can_cast for scalar inference for NEP 50

Co-authored-by: Matthew Roeschke <[email protected]>
…or 2.1.2) (pandas-dev#55749)

Backport PR pandas-dev#55747: DOC: Fix release date for 2.1.2

Co-authored-by: Thomas Li <[email protected]>
…calize_to_utc) (pandas-dev#55796)

Backport PR pandas-dev#55726: fix segfault with tz_localize_to_utc

Co-authored-by: William Ayd <[email protected]>
…dows default for Numpy 2.0) (pandas-dev#55851)

Backport PR pandas-dev#55817: COMPAT: Numpy int64 Windows default for Numpy 2.0

Co-authored-by: Matthew Roeschke <[email protected]>
… raising TypeError) (pandas-dev#55819)

* Backport PR pandas-dev#55473: TST: sort index with sliced MultiIndex

* BUG: DatetimeIndex.diff raising TypeError (pandas-dev#55761)

* BUG: DatetimeIndex.diff raising TypeError

* add test and whatsnew

* typing

* use Index

(cherry picked from commit f04da3c)

* fix whatsnew
…5855)

* TST: Make read_csv tests pyarrow 13 compatable on 2.1.x

* Skip on windows for ARROW_TIMEZONE_DATABASE
… data buffer has the wrong dtype / from_dataframe incorrect ) (pandas-dev#55863)

Backport PR pandas-dev#55227: BUG: Interchange object data buffer has the wrong dtype / from_dataframe incorrect

Co-authored-by: Marco Edward Gorelli <[email protected]>
Co-authored-by: MarcoGorelli <[email protected]>
…cs about NumPy's broadcasting) (pandas-dev#55896)

Backport PR pandas-dev#55427: DOC: Remove outdated docs about NumPy's broadcasting

Co-authored-by: cobalt <[email protected]>
…in _constructor_from_mgr for simple subclasses) (pandas-dev#55892)

Backport PR pandas-dev#55764: REGR: fix return class in _constructor_from_mgr for simple subclasses

Co-authored-by: Isaac Virshup <[email protected]>
…ExtensionType autoload (pandas-dev#55900)

Parquet/Feather IO: disable PyExtensionType autoload (pandas-dev#55894)

* Parquet/Feather IO: disable PyExtensionType autoload

* don't install hotfix for pyarrow >= 14.0.1

* move patching to extension type definitions

* expand error message

* fix compat for pyarrow not installed

* add whatsnew

(cherry picked from commit 851fea0)
…or 2.1.3) (pandas-dev#55913)

Backport PR pandas-dev#55907: DOC: Add release date for 2.1.3

Co-authored-by: Thomas Li <[email protected]>
…xample of NumPy's broadcasting to literal code block) (pandas-dev#55912)

Backport PR pandas-dev#55911: DOC: convert outdated example of NumPy's broadcasting to literal code block

Co-authored-by: Joris Van den Bossche <[email protected]>
@mroeschke
Copy link
Member

Thanks for the PR, but it appears there a lot of changes in unrelated files. Going to close this PR, but ensure that pull requests are made from the latest commit on main

@mroeschke mroeschke closed this Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants