@@ -580,29 +580,78 @@ def aggr(self, group, *attributes, exclude_nonmatching=False, **named_attributes
580580 aggregate = aggr # alias for aggr
581581
582582 # ---------- Fetch operators --------------------
583- @property
584- def fetch (self ):
583+ def fetch (
584+ self ,
585+ * attrs ,
586+ offset = None ,
587+ limit = None ,
588+ order_by = None ,
589+ format = None ,
590+ as_dict = None ,
591+ squeeze = False ,
592+ ):
593+ """
594+ Fetch data from the table (backward-compatible with DataJoint 0.14).
595+
596+ .. deprecated:: 2.0
597+ Use the new explicit output methods instead:
598+ - ``to_dicts()`` for list of dictionaries
599+ - ``to_pandas()`` for pandas DataFrame
600+ - ``to_arrays()`` for numpy structured array
601+ - ``to_arrays('a', 'b')`` for tuple of arrays
602+ - ``keys()`` for primary keys
603+
604+ Parameters
605+ ----------
606+ *attrs : str
607+ Attributes to fetch. If empty, fetches all.
608+ offset : int, optional
609+ Number of tuples to skip.
610+ limit : int, optional
611+ Maximum number of tuples to return.
612+ order_by : str or list, optional
613+ Attribute(s) for ordering results.
614+ format : str, optional
615+ Output format: 'array' or 'frame' (pandas DataFrame).
616+ as_dict : bool, optional
617+ Return as list of dicts instead of structured array.
618+ squeeze : bool, optional
619+ Remove extra dimensions from arrays. Default False.
620+
621+ Returns
622+ -------
623+ np.recarray, list[dict], or pd.DataFrame
624+ Query results in requested format.
585625 """
586- The fetch() method has been removed in DataJoint 2.0.
626+ import warnings
587627
588- Use the new explicit output methods instead:
589- - table.to_dicts() # list of dictionaries
590- - table.to_pandas() # pandas DataFrame
591- - table.to_arrays() # numpy structured array
592- - table.to_arrays('a', 'b') # tuple of numpy arrays
593- - table.keys() # primary keys as list[dict]
594- - table.to_polars() # polars DataFrame (requires pip install datajoint[polars])
595- - table.to_arrow() # PyArrow Table (requires pip install datajoint[arrow])
628+ warnings .warn (
629+ "fetch() is deprecated in DataJoint 2.0. " "Use to_dicts(), to_pandas(), to_arrays(), or keys() instead." ,
630+ DeprecationWarning ,
631+ stacklevel = 2 ,
632+ )
596633
597- For single-row fetch, use fetch1() which is unchanged.
634+ # Handle format='frame' -> to_pandas()
635+ if format == "frame" :
636+ if attrs or as_dict is not None :
637+ raise DataJointError ("format='frame' cannot be combined with attrs or as_dict" )
638+ return self .to_pandas (order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
598639
599- See migration guide: https://docs.datajoint.com/how-to/migrate-from-0x/
600- """
601- raise AttributeError (
602- "fetch() has been removed in DataJoint 2.0. "
603- "Use to_dicts(), to_pandas(), to_arrays(), or keys() instead. "
604- "See table.fetch.__doc__ for details."
605- )
640+ # Handle specific attributes requested
641+ if attrs :
642+ if as_dict or as_dict is None :
643+ # fetch('col1', 'col2', as_dict=True) or fetch('col1', 'col2')
644+ return self .proj (* attrs ).to_dicts (order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
645+ else :
646+ # fetch('col1', 'col2', as_dict=False) -> tuple of arrays
647+ return self .to_arrays (* attrs , order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
648+
649+ # Handle as_dict=True -> to_dicts()
650+ if as_dict :
651+ return self .to_dicts (order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
652+
653+ # Default: return structured array (legacy behavior)
654+ return self .to_arrays (order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
606655
607656 def fetch1 (self , * attrs , squeeze = False ):
608657 """
0 commit comments