{"record":{"id":"25a75872595cf839","repo":"pandas-dev/pandas","slug":"name-self-name-r-is-not-defined","errorCode":null,"errorMessage":"name {self.name!r} is not defined","messagePattern":"name (.+?) is not defined","errorType":"exception","errorClass":"NameError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/pytables.py","lineNumber":91,"sourceCode":"class Term(ops.Term):\n    env: PyTablesScope\n\n    def __new__(cls, name, env, side=None, encoding=None):\n        if isinstance(name, str):\n            klass = cls\n        else:\n            klass = Constant\n        return object.__new__(klass)\n\n    def __init__(self, name, env: PyTablesScope, side=None, encoding=None) -> None:\n        super().__init__(name, env, side=side, encoding=encoding)\n\n    def _resolve_name(self):\n        # must be a queryables\n        if self.side == \"left\":\n            # Note: The behavior of __new__ ensures that self.name is a str here\n            if self.name not in self.env.queryables:\n                raise NameError(f\"name {self.name!r} is not defined\")\n            return self.name\n\n        # resolve the rhs (and allow it to be None)\n        try:\n            return self.env.resolve(self.name, is_local=False)\n        except UndefinedVariableError:\n            return self.name\n\n    # read-only property overwriting read/write property\n    @property  # type: ignore[misc]\n    def value(self):\n        return self._value\n\n\nclass Constant(Term):\n    def __init__(self, name, env: PyTablesScope, side=None, encoding=None) -> None:\n        assert isinstance(env, PyTablesScope), type(env)\n        super().__init__(name, env, side=side, encoding=encoding)","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/computation/pytables.py#L73-L109","documentation":"Raised by Term._resolve_name in pandas.core.computation.pytables when a left-hand-side identifier in an HDFStore 'where' expression is not present in env.queryables - the dict of indexable columns and data_columns the table exposes. It is raised as NameError and tells you the column does not exist or is not queryable in the table.","triggerScenarios":"store.select('df', where='nonexistent_col > 5'); pd.read_hdf(path, 'df', where='missing == 3'); querying a column that exists in the DataFrame but was not declared as a data_column when written to HDF5.","commonSituations":"Writing a DataFrame to HDF5 without data_columns=True (only the index is queryable by default); typos in column names; assuming all columns are queryable; schema drift between writer and reader (column renamed/removed).","solutions":["Write the DataFrame with the column declared queryable: store.put('df', df, format='table', data_columns=['colname']) or data_columns=True for all columns.","Verify the column is queryable: print(store.get_storer('df').non_index_axes) and check the data_columns list.","Fix typos by listing available columns: print(store.get_storer('df').data_columns).","If the column isn't queryable, read the whole frame and filter in pandas: df = store.get('df'); df[df['col'] > 5]."],"exampleFix":"# before\nstore.select('df', where='value > 5')   # NameError if 'value' is not a data_column\n\n# after (declare at write time)\nstore.put('df', df, format='table', data_columns=['value'])\nstore.select('df', where='value > 5')\n# or filter in pandas:\ndf = store.get('df')\ndf[df['value'] > 5]","handlingStrategy":"validation","validationCode":"def assert_queryable(store, key, column):\n    storer = store.get_storer(key)\n    queryable = list((storer.data_columns or [])) + (storer.index_axes or [])\n    if column not in [getattr(a, 'name', None) for a in queryable]:\n        raise NameError(f'{column!r} is not queryable; declare it as a data_column')","typeGuard":"def is_queryable_column(store, key, column) -> bool:\n    try:\n        storer = store.get_storer(key)\n        names = [getattr(a, 'name', None) for a in (storer.data_columns or [])]\n        names += [getattr(a, 'name', None) for a in (storer.index_axes or [])]\n        return column in names\n    except Exception:\n        return False\n","tryCatchPattern":"try:\n    store.select('df', where=f'{col} > 5')\nexcept NameError as e:\n    if 'is not defined' in str(e):\n        # read all and filter in pandas\n        df = store.get('df')\n        result = df[df[col] > 5]\n    else:\n        raise","preventionTips":["Declare data_columns at write time for any column you intend to query.","Verify column names with store.get_storer(key).data_columns before selecting.","Use store.keys() to confirm the correct group/key."],"tags":["pandas","hdf5","pytables","where","column-names"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}