@@ -580,29 +580,82 @@ 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+ download_path = "." ,
593+ ):
594+ """
595+ Fetch data from the table (backward-compatible with DataJoint 0.14).
596+
597+ .. deprecated:: 2.0
598+ Use the new explicit output methods instead:
599+ - ``to_dicts()`` for list of dictionaries
600+ - ``to_pandas()`` for pandas DataFrame
601+ - ``to_arrays()`` for numpy structured array
602+ - ``to_arrays('a', 'b')`` for tuple of arrays
603+ - ``keys()`` for primary keys
604+
605+ Parameters
606+ ----------
607+ *attrs : str
608+ Attributes to fetch. If empty, fetches all.
609+ offset : int, optional
610+ Number of tuples to skip.
611+ limit : int, optional
612+ Maximum number of tuples to return.
613+ order_by : str or list, optional
614+ Attribute(s) for ordering results.
615+ format : str, optional
616+ Output format: 'array' or 'frame' (pandas DataFrame).
617+ as_dict : bool, optional
618+ Return as list of dicts instead of structured array.
619+ squeeze : bool, optional
620+ Remove extra dimensions from arrays. Default False.
621+ download_path : str, optional
622+ Directory for downloaded attachments. Default '.'.
623+
624+ Returns
625+ -------
626+ np.recarray, list[dict], or pd.DataFrame
627+ Query results in requested format.
585628 """
586- The fetch() method has been removed in DataJoint 2.0.
629+ import warnings
587630
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])
631+ warnings .warn (
632+ "fetch() is deprecated in DataJoint 2.0. "
633+ "Use to_dicts(), to_pandas(), to_arrays(), or keys() instead." ,
634+ DeprecationWarning ,
635+ stacklevel = 2 ,
636+ )
596637
597- For single-row fetch, use fetch1() which is unchanged.
638+ # Handle format='frame' -> to_pandas()
639+ if format == "frame" :
640+ if attrs or as_dict is not None :
641+ raise DataJointError ("format='frame' cannot be combined with attrs or as_dict" )
642+ return self .to_pandas (order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
598643
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- )
644+ # Handle specific attributes requested
645+ if attrs :
646+ if as_dict or as_dict is None :
647+ # fetch('col1', 'col2', as_dict=True) or fetch('col1', 'col2')
648+ return self .proj (* attrs ).to_dicts (order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
649+ else :
650+ # fetch('col1', 'col2', as_dict=False) -> tuple of arrays
651+ return self .to_arrays (* attrs , order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
652+
653+ # Handle as_dict=True -> to_dicts()
654+ if as_dict :
655+ return self .to_dicts (order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
656+
657+ # Default: return structured array (legacy behavior)
658+ return self .to_arrays (order_by = order_by , limit = limit , offset = offset , squeeze = squeeze )
606659
607660 def fetch1 (self , * attrs , squeeze = False ):
608661 """
0 commit comments